need help building GUI that plots data

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개)

Walter Roberson
Walter Roberson 2018년 4월 8일

0 개 추천

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일

0 개 추천

that helped, thanks

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

질문:

2018년 4월 6일

답변:

2018년 4월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by