フィルターのクリア

MATLAB GUI Popup Menu

17 ビュー (過去 30 日間)
John
John 2011 年 9 月 30 日
So I'm trying to create a popup menu whose options depend on another selection made earlier in the GUI. I know one can simply add the options in a pop up menu via the Property Inspector, however since the options may vary depending on what the user will choose earlier I can't do that. Is there any way I can add the options the pop up menu will have depending on what the user chooser earlier?

採用された回答

Matt Tearle
Matt Tearle 2011 年 9 月 30 日
Here's an example that I think is similar to what you're trying to do. It sounds like you're using GUIDE, in which case use the handles structure to access the handles of the appropriate uicontrol objects. But the key is using get to query the value of one menu that was chosen by the user, then using set to update the options in the other menu.
function objpick
figure;
uicontrol('units','normalized','position',[0.1,0.2,0.3,0.05],...
'style','popup','string',{'Fruits','Vegetables','Marsupials'},...
'value',1,'callback',@changetype);
hm2 = uicontrol('units','normalized','position',[0.6,0.2,0.3,0.05],...
'style','popup','string',{''},'value',1);
function changetype(hObj,~)
switch get(hObj,'value')
case 1
s = {'Apple','Banana','Pear'};
case 2
s = {'Cabbage','Leek','Eggplant','Spinach'};
case 3
s = {'Wombat','Platypus','Kangaroo'};
end
set(hm2,'string',s,'callback',@dosomething)
end
end
  1 件のコメント
John
John 2011 年 10 月 3 日
thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by