Appdesigner load m-file with dropdown

11 ビュー (過去 30 日間)
prrrrr
prrrrr 2020 年 7 月 7 日
回答済み: Sai Sri Pathuri 2020 年 7 月 10 日
I want to add an dropdown menu in the app designer.
with each option a stored m-file should be loaded. If possible the name should be there instead of option1/2/3. but I have no approach.
properties (Access = public)
var1=load('1.mat'); % specify the path to mat file missing
var2=load('2.mat');
var3=load('3.mat');
end
the rest unfortunately does not work

採用された回答

Sai Sri Pathuri
Sai Sri Pathuri 2020 年 7 月 10 日
You may follow these steps
  1. Open App Designer by typing appdesigner in command window and Select a Blank app
  2. Drag and drop the Drop Down menu from component library to design view
  3. In Component browser, change Items in drop-down section to None, MatFile1, MatFile2, MatFile3
  4. Go to Code view and add a callback by pressing '+' symbol in code browser and change component to Drop-Down
  5. Add this code in the new callback and save the app
value = app.DropDown.Value;
switch value
case 'MatFile1'
f = @(x) load(x, 'VarName1'); % VarName1 is the variable to be loaded from MatFile1
out = f(value);
assignin('base','VarName1',out.VarName1)
case 'MatFile2'
f = @(x) load(x, 'VarName2'); % VarName2 is the variable to be loaded from MatFile2
out = f(value);
assignin('base','VarName2',out.VarName2)
case 'MatFile3'
f = @(x) load(x, 'VarName3'); % VarName3 is the variable to be loaded from MatFile3
out = f(value);
assignin('base','VarName3',out.VarName3)
end
If the variable name is same for all file, you may remove switch condition

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by