Callback
Property
User Action Components That Use This
Property
WindowButtonU
pFcn
End user releases a mouse button. figure
WindowKeyPres
sFcn
End user presses a key while the
pointer is on the figure or any of
its child objects.
figure
WindowKeyRele
aseFcn
End user releases a key while the
pointer is on the figure or any of
its child objects.
figure
WindowScrollW
heelFcn
End user turns the mouse wheel
while the pointer is on the figure.
figure
How to Specify Callback Property Values
To associate a callback function with a UI component, set the value of one of the
component’s callback properties to be a reference to the callback function. Typically, you
do this when you define the component, but you can change callback property values
anywhere in your code.
Specify the callback property value in one of the following ways:
- “Specify a Function Handle” on page 10-7.
- “Specify a Cell Array” on page 10-8. This cell array contains a function handle as
the first element, followed by and any input arguments you want to use in the function. - “Specify an Anonymous Function” on page 10-9.
- “Specify a Character Vector Containing MATLAB Commands (Not Recommended)” on
page 10-9
Specify a Function Handle
Function handles provide a way to represent a function as a variable. The function must
be a local or nested function in the same file as the app code, or you can write it in a
separate file that is on the MATLAB path.
To create the function handle, specify the @ operator before the name of the function. For
example, this uicontrol command specifies the Callback property to be a handle to
the function pushbutton_callback:
Write Callbacks for Apps Created Programmatically