User`s guide

8 Programming a GUIDE GUI
Using Only the Index of the Selected Menu Item
This example retrieves only the index of the item selected. It uses a switch
statementtotakeactionbasedonthevalue. Ifthecontentsofthepop-up
menu are f ixed, then you can use this approach. Else, you can use the index
to retrieve the actual string for the selected item.
function popupm enu1 _Callback(hObject, eventdata, handles)
val = get(hObject,'Value');
switch val
case 1
% User selected the first item
case 2
% User selected the second item
% Proceed with callback...
You can also select a menu item programm atically by setting the pop-up
menu
Value property to the index o f the desired item . For example,
set(handles.popupmenu1,'Value',2)
selects the second item in the pop-up menu with Tag property popupmenu1.
Using the Index to Determine the Selected String
This example retrieves the actual string selected in the pop-up menu. It
uses the pop-up m enu
Value property to index into the list of strings. This
approach may be useful if your program dynamically loads the contents of the
pop-up m enu based o n user action and you need to obtain the selected string.
Note that it is necessary to convert the value returned by the
String property
from a cell array to a string.
function popupm enu1 _Callback(hObject, eventdata, handles)
val = get(hObject,'Value');
string_list = get(hObject,'String');
selected_string = string_list{val}; % Convert from cell array
% to string
% Proceed with callback...
Panel
Panels group GUI components and can make a GUI easier to understand by
visually grouping related controls. A panel can contain panels and button
8-38