Main Content


Return function handle to current position constraint function

getPositionConstraintFcn is not recommended. With the new ROIs, use the DrawingArea property instead. For more information, see Compatibility Considerations.


fcn = getPositionConstraintFcn(h) returns a function handle fcn to the current position constraint function of the ROI object h.

Input Arguments

collapse all

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

Output Arguments

collapse all

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

Version History

Introduced in R2008a

collapse all

R2018b: getPositionConstraintFcn is not recommended

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 Create ROI Shapes.

Using the new ROIs, you do not need to create and register a position constraint function. You use the DrawingArea property of the ROI to control where you can draw and move an ROI. Therefore, there is no need for a function to retrieve the current constraint function.

Update Code

Update all instances of getPositionConstraintFcn.

Discouraged UsageRecommended Replacement

This example creates a point ROI and uses the setPositionConstraintFcn method to confine ROI creation and movement to within the boundaries of the underlying image.

h = impoint(gca,20,60);
% Create a position constraint function.
x = get(gca,'XLim');
y = get(gca,'YLim');
fcn = makeConstrainToRectFcn('impoint',x,y);;
% Register the constraint function with the ROI.
% Retrieve the handle of the current position constraint function.
fcn = getPositionContraintFcn(h);

With the new ROIs, there is no equivalent to getting a handle to the current position constraint function. The new ROIs use the DrawingArea property to specify the limits of the area where you can create and move an ROI. For example, this code creates a 10-pixel margin inside the image boundary where you cannot draw or move the ROI.

h = drawpoint(gca,'Position',[20 60])
[height width] = size(I); %Get image dimensions
h.DrawingArea = [10,10,(width-20),(height-20)];