フィルターのクリア

Is it possible to have a switch case statement with the number of cases based on the length of a variable?

6 ビュー (過去 30 日間)
Hi
I am trying to build a GUI in MATLAB using GUIDE. I build up and store a database of household electrical appliances based on user inputs. I would like to create a pop-up menu which gives the user various options to display graphs of these appliances. Is it possible to make the number of options in the pop-up menu the same length as the number of appliances stored in the database bearing in mind the number of appliances is changeable. Your assistance on this matter would be much appreciated.
Thanks
Stuart

回答 (1 件)

PT
PT 2013 年 4 月 10 日
I am not aware there is any way to dynamically populate a switch statement. However, you can populate the popup menu during runtime.
Assuming some database structures:
Database = {
'television' 'television.mat'
'toaster' 'toaster.mat'
'refrigerator' 'refrigerator.mat'
'microwave' 'microwave.mat'
}
And in each mat file contains x and y variables for plotting.
In the Opening Function of the popup menu, you can do:
set(hObject, 'String', Database(:,1));
to populate the menu.
And in the Callback Function of the popup menu,
selected = get(hObject, 'Value');
load( Database(selected,2) );
plot( handles.axes1, x, y );
where axes1 is the tag for the plot box in your GUI.
  3 件のコメント
PT
PT 2013 年 4 月 10 日
Sorry I meant CreateFcn. OpeningFcn is for the entire GUI.
Stuart
Stuart 2013 年 4 月 10 日
That is ok no worries I will give this a go and see if I can get it to work.
Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by