if/else/then gui?

5 ビュー (過去 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 Center および File ExchangeClocks and Timers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by