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