Needs help in uploading only the needed file to the user interface
Show older comments
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.
Accepted Answer
More Answers (1)
Walter Roberson
on 10 Sep 2016
1 vote
When the directory is decided, use dir() to find the names of potential files. Set the String property of either a uicontrol('Style','popup') or 'style' 'listbox' to create the lists of files available to select from. When the user has made their selection, the Value property of the uicontrol will be set the the index of the name used. If you still have the list of files you could index into that; if not then you can pull out the String property of the uicontrol and index into it.
5 Comments
Anu Priya
on 10 Sep 2016
Edited: Walter Roberson
on 10 Sep 2016
Walter Roberson
on 10 Sep 2016
Please do not use a variable named path as that interferes with using the MATLAB path.
Walter Roberson
on 10 Sep 2016
We cannot answer your question yet, because we do not know which is the "needed" data set.
If you need to know that the user has selected a file, then test
if ischar(file)
If the user closes the uigetfile() dialog, or clicks on 'Cancel' then the output of uigetfile is numeric 0 (not the character '0'). uigetfile() waits until the user selects a file or closes the dialog or cancels, so you do not need to do any kind of checking like
while user_has_not_made_a_uigetfile_choice_yet() %NOT NEEDED
pause(2);
end
You just
[file, pathname] = uigetfile('*.csv;','Choose the data file');
if ~ischar(file)
error('You did not choose a file. I do not know what to do. I quit.')
end
data = xlsread( fullfile(pathname, file) ); %read the file
Anu Priya
on 11 Sep 2016
Walter Roberson
on 11 Sep 2016
If the file names are fixed then why ask the user to select a file name? At most you would need the user to select the directory, which you can do with uigetdir()
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!