
Callback Syntax and Arguments
8-11
Callback Syntax and Arguments
GUIDE defines conventions for callback syntax and arguments and
implements these conventions in the callback templates it adds to the M-file.
Each template is similar to this one for the
Callback subfunction for a push
button.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles) %#ok
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
...
The first comment line describes the event that triggers execution of the
callback. This is followed by the function definition line. The remaining
comments describe the input arguments.
Insert your code after the last comment.
Note You can avoid automatic generation of the callback comment lines for
new callbacks. In the
Preferences dialog box, select GUIDE and uncheck Add
comments for newly generated callback functions.
This topic discusses these aspects of the template:
• “Naming of Callback Functions” on page 8-11
• “Changing Callback Names Assigned by GUIDE” on page 8-12
• “Input Arguments” on page 8-13
• “The Handles Structure” on page 8-13
Naming of Callback Functions
The callback example above shows the following function definition:
function pushbutton1_Callback(hObject,eventdata,handles)
Commenti su questo manuale