Main Content

iptaddcallback

Add function handle to callback list

Description

iptaddcallback(obj,callback,@fun) adds the function fun to the list of functions to be called when the callback of graphics object obj executes.

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

example

ID = iptaddcallback(obj,callback,@fun) also returns an identifier, ID, for the callback function fun.

Examples

collapse all

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);

Input Arguments

collapse all

Graphics object, specified as a handle to a figure, axes, uipanel, or image graphics objects.

Callback property of the graphics object obj, specified as a character vector. For a list of callbacks for graphics objects, see Figure Properties, Axes Properties, Panel Properties, and Image Properties.

Data Types: char

Callback function, specified as a function handle. For more information, see Create Function Handle.

Data Types: function_handle

Output Arguments

collapse all

Callback identifier for function fun, returned as a positive integer.

Tips

  • 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, then iptaddcallback replaces that callback function with the iptaddcallback callback processor, and then adds the preexisting callback function to the iptaddcallback list.

Version History

Introduced before R2006a