Use drop down menu to select file to plot

Hi,
I have multiple .mat files in my folder that I load into matlab using dirfiles. How can I have a drop down menu or list that lets me select which file I want to plot and switch from one file to the other one?
for k = 1:numfiles
myfilename = dirfiles(k).name;
fullFileName = fullfile(PathName, myfilename);
mydata{k} = load(fullFileName);
end

댓글 수: 5

dpb
dpb 2021년 10월 17일
편집: dpb 2021년 10월 17일
See
doc uigetfile
to have user selection from git-go or populate a list box for the selection if know the root names to provide from--
doc listdlg
Konvictus177
Konvictus177 2021년 10월 17일
편집: Konvictus177 2021년 10월 17일
listdlg is a good workaround! How can I use listdlg while the figure is open to plot some other .mat file that is loaded into the workspace? This has to happen in a while loop I guess.
One of my apps uses a menu to select/change a workbook desired sheet -- the callback for the given menu action function looks like
% Menu selected function: BillingSheetMenu
function BillingSheetMenuSelected(app, event)
if ~exist(app.billQualFile,'file')
errordlg([app.billQualFile "Not Found. Must Set Billing File First."])
return
end
sheets=sheetnames(app.billQualFile);
iv=find(contains(sheets,app.billSheet,'IgnoreCase',false));
if isempty(iv), iv=1; end
ix=listdlg('PromptString','Select Billing Sheet','ListString',sheets,'selectionmode','single','initialvalue',iv);
if isempty(ix), ix=iv; end
app.billSheet=sheets(ix);
app.BillingSheetTextArea.Value=app.billSheet;
end
You'll have to have a callback function tied to something that would mimic something like the above with the content of the listbox being the files list.
The same app menu to select the file function uses uigetfile instead --
% Menu selected function: BillingFileMenu
function BillFileFunction(app, event)
filestr=fullfile(app.billPath,'*Bill*.xlsx');
[app.billFile,app.billPath]=uigetfile(filestr,'Select Desired Billing File',"MultiSelect","off");
try
app.BillingFolderTextArea.Value=app.billPath;
app.BillingFfileTextArea.Value=app.billFile;
app.billQualFile=fullfile(app.billPath,app.billFile);
%app.BillingSheetTextArea.Value=app.billSheet;
catch
% leave unchanged; if nothing there, catch it when trying to run update
end
filenames = {dirfiles.name};
[indx, tf] = listdlg('ListString', filenames, 'PromptString', 'Select a file');
if ~tf; return; end %user cancel
fullFileName = fullfile(PathName, filenames{indx});
mydata = load(fullFileName);
Konvictus177
Konvictus177 2021년 10월 18일
Thanks for the help.
I was able to use listdlg box and bring the listdlg box up again when a certain condition was met.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2021년 10월 17일

댓글:

2021년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by