Remove new-position callback from ROI object
removeNewPositionCallback is not recommended. With the new ROIs,
addlistener object function instead. For more information,
see Compatibility Considerations.
Create a line ROI object. Display the position of the line in the title. Use
addNewPositionCallback to update the title each time you move the
imshow('pout.tif') h = imline(gca,[10 100],[100 100]); id = addNewPositionCallback(h,@(pos) title(mat2str(pos,3)));
Move the line to observe the callback behavior.
After observing the callback behavior, remove the callback. The title no longer changes when you move the line.
Not recommended starting in R2018b
Starting in R2018b, a new set of ROI objects replaces the existing set of ROI objects. The new objects provide more functional capabilities, such as face color transparency. The new classes also support events that you can use to respond to changes in your ROI such as moving or being clicked. Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities and flexibility. For more information on creating ROIs using the new ROI functions, see ROI Creation Overview.
With the new ROIs, the
Position property contains the current
location of the ROI. To receive notification when this value changes, set up a
listener using the
function. To remove this callback, delete the listener object.
Update all instances of
|Discouraged Usage||Recommended Replacement|
This example uses the
imshow('cameraman.tif') h = imrect(gca, [10 10 100 100]); % Add callback that updates the title with position. id = addNewPositionCallback(h,@(p) title(mat2str(p,3))); % Remove position callback. Title no longer updates. removeNewPositionCallback(h,id);
Here is equivalent code, creating a new ROI object and
imshow('cameraman.tif') h = drawrectangle(gca,'Position',[10 10 100 100]); % Set up a listener for ROI moving events. el = addlistener(h,'MovingROI',@mymovecb) % Callback to update title with current position function mymovecb(src,evt) currpos = evt.CurrentPosition; title(mat2str(currpos,3)) end