필터 지우기
필터 지우기

Need help understanding the popup menu in GUI.

조회 수: 3 (최근 30일)
Matt Brown
Matt Brown 2015년 10월 15일
댓글: Geoff Hayes 2015년 10월 16일
I could use some clarification regarding the proper use of the popup menu in a GUI. Say I have a popup menu that has 'Option A' and 'Option B'. When I run the code, the figure is generated and the popup menu shows 'Option A'. However, the GUI doesn't recognize the popup menu until I select either Option A or Option B from the list.
Furthermore, when I try to call the current value of the popup menu (after it recognizes it) it returns all values, so it lists a the whole cell array defining the options... {'Option A', 'Option B'}.
My questions are this:
1. How can I initialize the popup menu so that it recognizes this input from launch?
2. How can I save and call just the current selection in the popup menu?
I have attached the files for reference.

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 10월 15일
Matt - use the Value property of the pop-up menu control to set and get the index of the selected item. For example, to default the menu to the second item in the list, copy the following into the OpeningFcn of your GUI (I'm assuming that you are using GUIDE to create your GUI)
set(handles.popupmenu1,'Value',2);
So now, when the GUI is launched, the second item will be selected. Now, to get the index of the item that has been selected, do the following (in whatever callback that is appropriate)
idx = get(handles.popupmenu1,'Value');
Try the above and see what happens!
  댓글 수: 3
Matt Brown
Matt Brown 2015년 10월 16일
Actually.... I am still having an issue. I am able to call up whatever value is shown after an initial selection, but the default value is still not getting used at launch. I have boiled this down to a much simpler GUI that basically displays whatever selection you have. What I would like to be able to do is have this display 'A' when the program launches, then A, B, C or D once they are selected from the popup menu.
See attached help.m file.
What am I piece of this puzzle am I missing?
Geoff Hayes
Geoff Hayes 2015년 10월 16일
Matt - given the code, I see that you set the first element in the list as
set(handles.popupmenu1,'Value',1)
so you should see A as the selected element in the popup menu when you launch the GUI. You then mention ...when the program launches, then A, B, C or D once they are selected from the popup menu.... This statement suggests that you wish to allow the user to select A even though it has already been selected. What are you expecting to happen immediately when the user launches the GUI? If the default setting for this menu is A do you wish to have some code fire that would be the same as if the user had selected A from the menu? (Since A is already selected then the user won't be able to select it until this option has changed.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by