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.

addNewPositionCallback

Add new-position callback to ROI object

addNewPositionCallback is not recommended. Use one of the ROI classes instead, described in ROI Creation Overview.

Syntax

id = addNewPositionCallback(h,fcn)

Description

example

id = addNewPositionCallback(h,fcn) adds the function handle fcn to the list of new-position callback functions of the ROI object h. Whenever the ROI object changes its position, each function in the list is called with the syntax:

fcn(pos)

pos is of the form returned by the object's getPosition method. The return value, id, is used only with removeNewPositionCallback.

Examples

Display Updated Position in Title

Create a rectangle ROI object. Display the position of the rectangle in the title. The title updates when you move the rectangle.

imshow('cameraman.tif')
h = imrect(gca, [10 10 100 100]);
addNewPositionCallback(h,@(p) title(mat2str(p,3)));

Now drag the rectangle using the mouse to observe the callback behavior.

Input Arguments

collapse all

ROI object, specified as an imellipse, imfreehand, imline, impoint, impoly, or imrect object.

Function handle, specified as a handle. The function must accept a numeric array as input. The array must have the same form as returned when calling getPosition on the object. For more information, see Create Function Handle (MATLAB).

Output Arguments

collapse all

Identifier of new-position callback function, returned as a struct.

Introduced in R2008a