need help building GUI that plots data

1 次查看(过去 30 天)
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

回答(3 个)

Brian Rreid
Brian Rreid 2018-4-7
bump

Walter Roberson
Walter Roberson 2018-4-8
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 2018-4-9
that helped, thanks

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by