Main Content

addNewPositionCallback

添加新位置调ROI object

addNewPositionCallbackis not recommended. With the new ROIs, use theaddlistenerobject function instead. For more information, seeCompatibility Considerations.

Description

example

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

fcn(pos)

posis of the form returned by the object'sgetPositionmethod. The return value,id, is used only withremoveNewPositionCallback.

Examples

collapse all

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 animellipse,imfreehand,imline,impoint,impoly, orimrect目的。

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 callinggetPositionon the object. For more information, seeCreate Function Handle.

Output Arguments

collapse all

Identifier of new-position callback function, returned as astruct.

Version History

Introduced in R2008a

expand all

Not recommended starting in R2018b