Creating Graphical User Interfaces Previous page   Next Page

Callbacks in Programmatically Created GUIs

Although you may eventually want to define your own syntactical conventions, the following provides a good place to start.

Function Definition

Your function definition could look something like this:

The comment line describes the event that triggers execution of the callback.

To help you remember the component and callback property with which this callback is associated, construct the callback name by appending an underscore (_) and the name of the callback property to the component's Tag property. In the example above, pushbutton1 is the Tag property for the push button, and Callback is one of the push button's callback properties. See Associating Callbacks with Components for more information.

Input Arguments

If you use a handle to specify the callback in the component callback property, i.e., @pushbutton_callback as shown here

MATLAB automatically passes the handle of the component for which the event was triggered and eventdata as the first two arguments of the callback. The function definition line for your callback must account for these two arguments. The second element of the cell array, handles in the example above, becomes the third argument of the callback. For example,

The input arguments are defined as:

If you make any changes to this structure, you must explicitly save it before exiting the callback. To do this, you can use either guidata or setappdata. See Managing Application-Defined Data for information about using these functions.


Previous page  Callback Conventions in GUIDE Initialization Callbacks in GUIDE Next page

© 1994-2005 The MathWorks, Inc.