need help building GUI that plots data

조회 수: 13 (최근 30일)
Brian Rreid
Brian Rreid 2018년 4월 6일
답변: Brian Rreid 2018년 4월 9일
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