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 Comments

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
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);
Thanks for the help.
I was able to use listdlg box and bring the listdlg box up again when a certain condition was met.

Sign in to comment.

Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 17 Oct 2021

Commented:

on 18 Oct 2021

Community Treasure Hunt

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

Start Hunting!