Main Content

setPosition

(Not recommended) Move ROI object to new position

setPosition is not recommended. With the new ROIs, set the value of the Position property instead. For more information, see Compatibility Considerations.

Description

setPosition(h,pos) moves the position of the ROI object, h, to the location specified by pos.

setPosition(h,x,y) specifies the new x- and y-coordinates of points of a line or point ROI object.

Input Arguments

collapse all

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

New position of the ROI object, specified as a numeric array. The shape of the array depends on the type of ROI object.

ROI ObjectPosition
imellipse4-element vector of the form [xmin ymin width height], representing the new size and position of a bounding box around the ellipse. The new size of the bounding box is width-by-height pixels. The upper-left corner of the box is at the new (x,y) coordinate (xmin,ymin).
imline2-by-2 matrix of the form [x1 y1; x2 y2], representing the new position of the two endpoints of the line.
impoint1-by-2 vector of the form [x y].
impolyn-by-2 matrix. The two columns define the new x- and y-coordinates, respectively, of each of the n vertices.
imrect4-element vector of the form [xmin ymin width height]. The new size of the rectangle is width-by-height pixels. The upper-left corner of the rectangle is at the new (x,y) coordinate (xmin,ymin).

New x-coordinate of points.

  • If h is an imline object, then x is a 2-element vector that represents the x-coordinates of the two line endpoints.

  • If h is an impoint object, then x is a numeric scalar that represents the x-coordinate of the single point.

New y-coordinate of points.

  • If h is an imline object, then y is a 2-element vector that represents the y-coordinates of the two line endpoints.

  • If h is an impoint object, then y is a numeric scalar that represents the y-coordinate of the single point.

Version History

Introduced in R2008a

collapse all

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

To specify the current location of the ROI, assign a value to the Position property of the ROI.

Update Code

Update all instances of setPosition method.

Discouraged UsageRecommended Replacement

This example sets the current location of the ROI using the setPosition object function.

imshow('cameraman.tif');
h = imrect(gca,[10 10 100 100]);
setPosition(h,[20 20 200 200]);;

Create one of the new ROI objects and replace use of the setPosition object function with assigning a value to the Position property of the ROI.

imshow('cameraman.tif');
h = drawrectangle(gca,'Position',[10 10 100 100]);
h.Position = [20 20 200 200];