This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Add function handle to callback list


ID = iptaddcallback(obj,callback,func_handle)


ID = iptaddcallback(obj,callback,func_handle) adds the function handle func_handle to the list of functions to be called when the callback specified by callback executes. callback specifies the name of a callback property of the graphics object specified.

iptaddcallback returns a unique callback identifier, ID, that can be used with iptremovecallback to remove the function from the callback list.

iptaddcallback can be useful when you need to notify more than one tool about the same callback event for a single object.


Callback functions that have already been added to an object using the set command continue to work after you call iptaddcallback. The first time you call iptaddcallback for a given object and callback, the function checks to see if a different callback function is already installed. If a callback is already installed, iptaddcallback replaces that callback function with the iptaddcallback callback processor, and then adds the preexisting callback function to the iptaddcallback list.


Create a figure and register two callback functions. Whenever MATLAB® detects mouse motion over the figure, function handles f1 and f2 are called in the order in which they were added to the list.

figobj = figure;
f1 = @(varargin) disp('Callback 1');
f2 = @(varargin) disp('Callback 2');
iptaddcallback(figobj, 'WindowButtonMotionFcn', f1);
iptaddcallback(figobj, 'WindowButtonMotionFcn', f2);

Introduced before R2006a