Need help understanding the popup menu in GUI.
2 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!