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.
dpb
dpb 2021 年 10 月 17 日
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
Walter Roberson
Walter Roberson 2021 年 10 月 17 日
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 ExchangeApp 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