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

11 views (last 30 days)
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

Answers (1)

PT
PT on 10 Apr 2013
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 Comments

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!