Creating Graphical User Interfaces    

Generating Callback Function Prototypes

When you select Generate callback function prototypes in the GUIDE Application Options dialog, GUIDE adds a subfunction to the application M-file for any component you add to the GUI (note that frame and static text components do not use their Callback property). You must then write the code for the callback in this subfunction.

GUIDE also adds a subfunction whenever you edit a callback routine from the right-click context menu.

Callback Function Syntax and Naming

The callback function syntax is of the form

The arguments are listed in the following table.

Callback Function Arguments
h
The handle of the object whose callback is executing.
eventdata
Empty, reserved for future use.
handles
A structure containing the handles of all components in the GUI whose fieldnames are defined by the object's Tag property. Can also be used to pass data to other callback functions or the main program.
varargin
A variable-length list of arguments that you want to be passed to the callback function.

For example, if you create a layout having a push button that has a Tag property set to pushbutton1, then GUIDE generates this subfunction in the application M-file.

GUIDE then sets the Callback property of this push button to

where:

If you want to pass additional arguments to the push button's callback routine, edit the Callback property in the Property Inspector to add a comma-separated list of arguments (which are then handled by the varargin argument in the subfunction).

For example, it you want to add two arguments to the callback of a push button in the application M-file named MyGui.m, you need to edit the syntax in two places:


 Generating the FIG-File and the M-File Application Allows Only One Instance to Run