MATLAB: Generate filepath for opening file from user selected listbox inputs

filenamefilepathguilistboxnum2str

I am trying to use user selected inputs to find a specific filename/location.
I have a large number of tests stored in a folder and I want a specific file to be loaded depending on the user inputs to use for subsequent analysis.
The filenames have common string with variable values based on the value of what is tested. What I want is to use the selected user input to fill the variable values to build a filename to load based on what is entered,
Example filename: Filename = ‘\Drive1\Main\Trial\Test\70_205_1800_445_5.6.csv
Where 70, 200, 354, 1.3, 500 are variables of the test
The GUI gives a better understanding on what i'm trying to achieve
Look to accomplish:
A = 70;
B = 205;
C = 1800;
D = 445;
E = 5.6;
Filename_Common = ‘\Drive1\Main\Trial\Test\';
Filename_constructed = Filename_Common,A_B_C_D_E;
Filename = filename_constructed;

Best Answer

  • root = '\Drive1\Main\Trial\Test'
    filename = sprintf('%d_%d_%d_%d_%g', A, B, C, D, E);
    fullpath = fullfile(root, filename);