MATLAB: Need help understanding the popup menu in GUI.

guipopup menu

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.

Best Answer

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!