Main Content


Set closure behavior of ROI object

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


setClosed(h,TF) sets whether the ROI object, h, is closed after the last point is selected.

Input Arguments

collapse all

ROI object, specified as an imfreehand or impoly object.

ROI object is closed, specified as true or false. When set to true, a straight line connect the endpoints of the ROI object to create a closed region. If set to false, the endpoints are not connected and the region is open.

Data Types: logical

Version History

Introduced in R2007b

collapse all

R2018b: setClosed 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.

In the existing ROIs, you can control whether a hand-drawn shape or a polygonal shape are closed or open. By default, when you double-click to draw the final vertex of one of these shapes, the ROI draws a line between the last vertex and the first vertex to close the shape. Using the setClosed method, you can create an open hand-drawn shape or polyline. With the new ROIs, the Freehand and AssistedFreehand shapes support a Closed property that you can use to specify whether the shape is closed or open. The new ROIs support both a polygon (closed) and a polyline (open) shape, so there is no need for these ROIs to support a Closed property.

Update Code

Update all instances of setClosed.

Discouraged UsageRecommended Replacement

This example creates a polygonal ROI and uses the setClosed method to turn the closed polygon into an open polyline.

h = impoly(gca,[10 10; 50 10; 20 100]);

To create an open polyline ROI, replace the call to the impoly with drawpolyline (or thePolyline object). Use drawpolygon (or the Polygon object) to create a closed polygonal shape.

h = drawpolyline(gca,'Position',[10 10; 50 10; 20 100]);

This example creates a hand-drawn ROI and uses the setClosedmethod to turn the closed shape into an open shape.

h = imfreehand;

To create an open, hand-drawn ROI shape, replace the call to imfreehand with drawfreehand or drawassisted. You can also create Freehand or AssistedFreehand objects. Use the Closed property to turn the closed shape into an open shape.

h = drawfreehand;
h.Closed = false;