Main Content

makeConstrainToRectFcn

Create rectangularly bounded drag constraint function

makeConstrainToRectFcn is not recommended. With the new ROIs, use the DrawingArea property instead. For more information, see Version History.

Description

fcn = makeConstrainToRectFcn(roi,x,y) creates a position constraint function for draggable tools of a given ROI type. The position of the tool is constrained by rectangular boundaries described by position vectors x and y.

example

Examples

collapse all

Display an image.

imshow('cell.tif')

Create an impoint object at the (x,y) coordinate (20,60). In an image, the positive y direction is downwards.

h = impoint(gca,20,60);

Figure contains an axes object. The hidden axes object contains 3 objects of type line, image.

Make a function that constrains the impoint to the image limits.

x = get(gca,'XLim');
y = get(gca,'YLim');
fcn = makeConstrainToRectFcn('impoint',x,y);

Apply the constraint function to the impoint. Try dragging the point past the boundary of the image. The constraint function prevents the point from crossing the image boundary.

setPositionConstraintFcn(h,fcn);

Input Arguments

collapse all

ROI type, specified as 'imellipse', 'imfreehand', 'imline', 'impoint', 'impoly', or 'imrect'.

Data Types: char | string

Rectangular boundaries in the x direction, specified as a 2-element numeric vector of the form [xmin xmax].

Rectangular boundaries in the y direction, specified as a 2-element numeric vector of the form [ymin ymax].

Output Arguments

collapse all

Function handle, returned as a handle. For more information, see Create Function Handle.

Version History

Introduced in R2006a

expand all