User`s guide
WriteCodeforCallbacks
You can concatenate commands in a string callback. This one, for example,
adds a title to the plot it creates.
set(hb,'Callback',...
'plot(myvar,''--m''); title(''String Callback'')')
Note Double single quotation marks are needed around any strings that
exist within the string.
Use Function Handle Callbacks
The most important things to remember about using function handles (a
function name preceded by an at s ign, for example,
@my_function)are:
• Function handles are names of functions within code files, not file names.
• You cannot place functions within MATLAB scripts.
• The function need not exist when callbacks using it are declared.
• When the callback executes, the file that defines the function must be on
your path.
• You cannot follow the function handle in a
Callback property definition
with arguments unless you wrap everything in a cell array.
• Your callback function declarations must include two initial arguments
that Handle Graphics automatically provides, commonly called
(hObject,eventdata).
• These two arguments (the handle of the object issuing the callback and
event data it option a lly provides ) must not appear in the
Callback property
definition.
Here is an example of declaring a callback when defining a uicontrol:
figure
uicontrol('Style','slider','Callbac k',@display_slider_value )
Here is the definition of the function in the GUI code file. The callback prints
the value of the slider when you adjust it:
12-13