Effacer les filtres
Effacer les filtres

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

7 vues (au cours des 30 derniers jours)
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

Réponses (1)

PT
PT le 10 Avr 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 commentaires
PT
PT le 10 Avr 2013
Sorry I meant CreateFcn. OpeningFcn is for the entire GUI.
Stuart
Stuart le 10 Avr 2013
That is ok no worries I will give this a go and see if I can get it to work.
Thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by