MATLAB Object-Oriented Programming

(Joyce) #1

For static methods, the required class name ensures MATLAB dispatches to the method of
the specified class:


@MyClass.methodName


Define the static callback method with two input arguments — the event source handle
and the event data


The function signature would be of this form:


function methodName(src,eventData)


Passing Extra Arguments


If you want to pass arguments to your callback in addition to the source and event data
arguments passed by MATLAB, you can use an anonymous function. The basic syntax for
an anonymous function that you assign to the graphic object's Callback property
includes the object as the first argument:


@(src,event)callbackMethod(object,src,eventData,arg1,...argn)


The function signature would be of this form:


function methodName(obj,src,eventData,varargin)
...
end


Use a Class Method for a Slider Callback


This example shows how to use a method of your class as a callback for an uicontrol
slider.


The SeaLevelSlider class creates a slider that varies the color limits of an indexed
image to give the illusion of varying the sea level.


Class Definition


Define SeaLevelSlider as a handle class with the following members:



  • The class properties store figure and axes handles and the calculated color limits.

  • The class constructor creates the graphics objects and assigns the slider callback.


Class Methods for Graphics Callbacks
Free download pdf