User`s guide

WriteCodeforCallbacks
that you specify. Place single quotes around the function name and any literal
string arguments, but not around workspace variable name arguments. The
function must exist on the MATLAB path, and needs to have at least two
arguments. The f irst two (which MAT LAB automatically inserts) are
The handle of the component whose callback is now being called.
Event data (a MATLAB struct that several figure and GUI component
callbacks provide, but most pass an empty matrix). See “Callbacks that
Pass Event Data” on page 12-18 for specific details.
Be sure not to include the handle and event data arguments
when you declare a component’s callback (for example,
set(hb,'Callback',{'pushbutton_call back',myvar,'--m'})),
but do include them in the definition of the callback, as described in the
following paragraph.
These two arguments are followed by whatever arguments you include
when you specify the callback for the component. Code to e xecute
'pushbutton_callback' might look like this:
function pushbu tton _callback(hObject, eventdata, var1, va r2)
plot(var1,var2)
The arguments you define can be variables, constants, or strings. Any
variables the callback u ses as arguments must exist in the current workspace
at the time you define the callback property. In the above example, the value
of the first argument (variable
myvar) is copied into the callback wh en setting
it. C onsequently, if
myvar does not currently exist, you receive an error:
??? Undefined function or vari able 'myvar'.
If myvar changes or is deleted after defining the callback, the original value
will still be used.
The second argument (
'--m') is a string literal LineSpec that does not refer
to any v ariable and, therefore, cannot raise an error when you specify the
callback—unless the function’s argument list does not include it.
To use this G UI, create a code file called
pushbutton_callback.m containing
the following code:
12-15