MATLAB: Needs help in uploading only the needed file to the user interface

uploaduser interface

I am working on a project where i am having 3 data sets say a,b,c which is saved in the .csv format. In the user interface i want to upload those files,for which i am having 3 browse buttons in separate sections.So how can i allow the user to select only the intended file using the browse button. Means i want the user to select only the file a.csv in the section for a using the particular browse button and b.csv in the section for b with the corresponding browse button. Is it possible to do so? All the data sets are saved in the same folder.

Best Answer

This is easy: simply tell uigetfile exactly which filenames you want the user to choose from, and it will only let them select from those exact files. This is much simpler than letting the user select any CSV file and then doing some awkward checking afterwards.
files = {'A.csv';'B.csv';'C.csv'}; % the permitted filenames
str = sprintf(';%s',files{:});
[fName,fPath,idx] = uigetfile({str(2:end),'CSV file'})
Remember to check if the user closed the dialog box:
assert(idx>0,'User closed the dialog box!')
Related Question