User`s guide

Create Menus in a GUIDE GUI
opened. If you clear this option, the menu item appears dimmed when the
menu is first opened, and the user cannot select it.
Specify a Callback for the menu that performs the action a ssociated with
the menu item. If you have not yet saved the GUI, the default value is
%automatic. When you save the GUI, and if you have not changed this
field, GUIDE automatically creates a callback in the code file using a
combination of the Tag field and the GUI filename. The callback’s name
does not display in the Callback field of the Menu Editor, but selecting the
menu item does trigger it.
You can also type an unquoted string into the Callback field to serve as
a callback. It can be any valid MATLAB expression or command. For
example, the string
set(gca, 'Color ', 'y')
sets the current axes background color to yellow. However, the preferred
approach t o performin g this operation is to place the call ba c k in the GU I
code file. This avoids the use of
gca, which is not a lways reliable when
several figures or axes exist. Here is a version of this callback coded as a
function in the GUI code file:
function axesye llow _Callback(hObject, eventdata, handles)
% hObject handle to axesyellow (see GCBO)
% eventdata re serv ed - to be defi ned in a future ver sion of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.axes1,'Color','y')
This code sets the background color of the GUI axes with T ag axes1 no
matter to what obje ct the context menu is attached to.
If you enter a callback string in the Menu Editor, it overrides the callback
for the item in the code file, if any has been saved. If you delete a string you
have entered in the Callback field, the callback for the item in the GUI
code file (if any) is executed when GUI runs and the item is selected.
See “Menu Item” on page 8-59 for more information about specifying
this field and for program ming menu items. For another example of
programming context menus in GUIDE, see “GUI to Interactively Explore
Data in a Table (GUIDE)” on page 10-31.
6-119