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
function
objectTag
_Callback
(h,eventdata,handles,varargin)
The arguments are listed in the following table.
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.
function pushbutton1_Callback(h,eventdata,handles,varargin)
GUIDE then sets the Callback
property of this push button to
mygui('pushbutton1_Callback',gcbo,[],guidata(gcbo))
mygui
- is the name of the FIG-file saved for this GUI.pushbutton1_Callback
- is the name of the callback subfunction.gcbo
- is a command that returns the handle of the push button.[]
- is an empty matrix used as a place holder for the eventdata
argument.guidata(gcbo)
- gets the handles
structure from the figure's application data.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:
function varargout = pushbutton1_Callback(h,eventdata,handles,arg1,arg2)
![]() | Generating the FIG-File and the M-File | Application Allows Only One Instance to Run | ![]() |