Borrar filtros
Borrar filtros

MATLAB GUI Popup Menu

17 visualizaciones (últimos 30 días)
John
John el 30 de Sept. de 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?

Respuesta aceptada

Matt Tearle
Matt Tearle el 30 de Sept. de 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 comentario
John
John el 3 de Oct. de 2011
thanks for the help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by