need help building GUI that plots data

10 views (last 30 days)
Brian Rreid
Brian Rreid on 6 Apr 2018
Answered: Brian Rreid on 9 Apr 2018
Hey everyone,
I am trying to build a GUI that allows me to open a folder, load the files into a list, and choose a file and then plot the data from that file. So far I have been able to build it to open a folder, but it will not show the particular files that I want. Any help would be appreciated.
function homework8
f=figure;
a=axes('Position',[0.1300 0.1317 0.4593 0.7731])
listbox=uicontrol('style','list','position',....
[346.3333 54.3333 135.0000 283.3334]);
btn=uicontrol('parent',f,'style','pushbutton','position',...
[344.6667 349.6667 135.6667 30.3333],'String','Select Folder','Callback',@openfolder);
%%Callbacks
function openfolder(~,~)
uigetdir
files=dir;
listbox.String={files(:).name};
end
end

Answers (3)

Brian Rreid
Brian Rreid on 7 Apr 2018
bump

Walter Roberson
Walter Roberson on 8 Apr 2018
uigetdir() does not change directories, it only returns the directory name.
folder = uigetdir();
if ~ischar(folder); return; end %user cancel
dinfo = dir(folder);
dinfo([dinfo.isdir]) = []; %throw away directories including . and ..
shortnames = {dinfo.name};
fullnames = fullfile(folder, shortnames);
You can set the ListBox to the full names, or you can set the ListBox to the short names and also save the folder information somewhere. When you go to process the file you will need the fully qualified name, either because that is what is immediately available from the list box, or by recalling the folder name and using it to qualify the short name.

Brian Rreid
Brian Rreid on 9 Apr 2018
that helped, thanks

Categories

Find more on Environment and Settings 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!