主要内容

setPositionConstraintFcn

Set position constraint function of ROI object

setPositionConstraintFcnis not recommended. With the new ROIs, use theDrawingAreaproperty instead. For more information, see兼容性有限公司nsiderations.

Description

example

setPositionConstraintFcn(h,fcn)sets the position constraint function of the ROI objecthto be the specified function handle,fcn. Whenever the object is moved because of a mouse drag, the constraint function is called using the syntax:

constrained_position = fcn(pos)

Examples

Update Title when Rectangle Moves

Display a rectangle ROI over an image. Display the position of the rectangle in the title. The title updates when you move the rectangle. Try dragging one side of the rectangle outside the boundary of the image.

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

Specify a position constraint function usingmakeConstrainToRectFcnto keep the rectangle inside the originalXLimandYLimranges.

fcn = makeConstrainToRectFcn('imrect'甘氨胆酸,(,'XLim'),get(gca,'YLim')); setPositionConstraintFcn(h,fcn);

Now drag the rectangle using the mouse. Observe that the rectangle can no longer extend past the image boundary.

Input Arguments

collapse all

ROI object, specified as animellipse,imline,impoint,impoly, orimrectobject.

Function handle, specified as a handle. You can use themakeConstrainToRectFcnto create this function. The function must accept a numeric array as input, and it must return a numeric array as output. Both arrays must have the same form as returned when callinggetPositionon the object. For more information, seeCreate Function Handle.

兼容性有限公司nsiderations

expand all

Not recommended starting in R2018b

Introduced in R2008a