MATLAB GUI Popup Menu

35 views (last 30 days)
John
John on 30 Sep 2011
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?

Accepted Answer

Matt Tearle
Matt Tearle on 30 Sep 2011
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

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!