Azzera filtri
Azzera filtri

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

6 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

PT
PT il 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 Commenti

Accedi per commentare.

Categorie

Scopri di più su App Building in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by