Filter löschen
Filter löschen

MATLAB GUI Popup Menu

17 Ansichten (letzte 30 Tage)
John
John am 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?

Akzeptierte Antwort

Matt Tearle
Matt Tearle am 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
  1 Kommentar
John
John am 3 Okt. 2011
thanks for the help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by