필터 지우기
필터 지우기

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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by