User`s guide
12 Code a Programmatic GUI
Note Unless you declare them as string s (with required arguments, as
described in “Use String Callbacks” on page 12-12), do not use regular
functions as callbacks. If you do, the functions can generate errors or
behave unpredictably. Because MATLAB GUI component callbacks include
autogenerated arguments, you cannot simply specify a regular MATLAB or
toolbox function name or function handle (for example,
plot or @pl ot)asa
callback.
Furthermore, callback function signatures generated by GUIDE include a
third autogenerated argument,
handles. To learn more about how GUIDE
handles callbacks, see “Customizing Callbacks in GUIDE” on page 8-15.
For more information on using function handles, see “Function Handle
Callbacks”. See “Kinds of Callbacks” on page 12-8 for a summary of available
callbacks. See the component property reference pages for information about
the specific types of callbacks each type of component supports.
Callbacks that Pass Event Data
Certain figure and GUI component callbacks provide data describing
user-generated eve nts in the
eventdata argument. When p resent, it occupies
the second argument to the callback. If there is no event data for a callback,
the argument is an empty matrix . For example, a push button;s
KeyPressFcn
callback receives event data as follows.
function pushbutton1_KeyP ressFcn(hObject, eventdata)
% hObject handle to pushbutton1 (see GCB O)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was presse d
% Modifier: name(s) of the modifier key(s)(i.e., control, shift) pressed
The f ollowing table lists callbacks that pro vide event data a nd the components
to which they apply. Click the links to the appropriate property reference
pages for details.
12-18