if/else/then gui?

4 次查看(过去 30 天)
James Hendren
James Hendren 2013-7-17
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

采纳的回答

Image Analyst
Image Analyst 2013-7-17
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 个评论
Image Analyst
Image Analyst 2013-7-17
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
Image Analyst 2013-7-17
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Clocks and Timers 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by