if/else/then gui?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
So in my gui I have 3 popup menus each with 2 selections. I need to base code on each selection. for example
if get(popupmenu1.handles,'value')==1
(insert code here) for value of popupmenu 2
(insert code here) for value of popupmenu 3
Inesrt my own function to be run dependent on the three values
I would need code that would get the value from popupmenu2, and then 3. Then I would run my a specific fitting procedure for the selections. By combinatorics there should be 8 combinations, and I would like my code to be simple. Can anyone help with that? Thanks in advance
0 Commenti
Risposta accettata
Image Analyst
il 17 Lug 2013
What's the difficulty? You already know how to get the selections:
popupValue1 = get(popupmenu1.handles,'value');
popupValue2 = get(popupmenu2.handles,'value');
popupValue3 = get(popupmenu3.handles,'value');
And you know how (or should know how) to construct if/then/else blocks, so where are you having trouble?
if popupValue1==1 && popupValue2==1 && popupValue3==1
% Some code
elseif popupValue1==1 && popupValue2==1 && popupValue3==2
% Some code
elseif popupValue1==1 && popupValue2==2 && popupValue3==1
% Some code
elseif popupValue1==1 && popupValue2==2 && popupValue3==2
% Some code
elseif popupValue1==2 && popupValue2==1 && popupValue3==1
% Some code
elseif popupValue1==2 && popupValue2==1 && popupValue3==2
% Some code
elseif popupValue1==2 && popupValue2==2 && popupValue3==1
% Some code
elseif popupValue1==2 && popupValue2==2 && popupValue3==2
% Some code
end
There's your eight possible cases, but I think you already knew that, so please clarify.
2 Commenti
Image Analyst
il 17 Lug 2013
James comment moved here:
I wanted to know if there was a cleaner way to do it...
So it would retrieve the values of 1,2,and 3 without having to type all the steps per se
I was wondering if it could be done in 3 steps rater than 8
Image Analyst
il 17 Lug 2013
You can't retrieve them all without retrieving them all, with get(). I think 3 ifs with ifs nested even deeper is a lot more complicated than the straightforward and easy-to-understand way I gave.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Clocks and Timers 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!