User`s guide

Examples: Program GUI C omponents
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(pmh,'Value',2)
selects the second item in the pop-up menu with handle pmh.
Use the Index to Determine the Selected String. This exam ple retrieves
the actual string selected in the pop-up menu. It u ses the pop-up menu
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 menu bas ed on 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,event data)
val = get(hObject,'Value');
string_list = get(hObject,'String');
selected_string = string_list{val}; % Convert from cell array
% to string
% Proceed with callback...
hObject
is the handle of the component for which the event was triggered.
Push Button
This example contains only a push button. Clicking the button closes the GUI.
This is the push button’s Callback callback. It displays the string Goodbye at
the command line and then closes the GUI.
function pushbu tton 1_Callback(hObject,even tdata)
display Good bye
12-25