Main Content

wait

(Not recommended) Block MATLAB command line until ROI creation is finished

wait is not recommended. Use the wait method associated with the new ROIs instead. For more information, see Version History.

Description

pos = wait(h) blocks execution of the MATLAB® command line until you finish positioning the ROI object h. Indicate completion by double-clicking on the ROI object. The function returns the position, pos, of the ROI object.

example

v = wait(he) blocks execution of the MATLAB command line until you finish positioning the ellipse ROI object he. Indicate completion by double-clicking on the ROI object. The function returns the coordinates of vertices, v, along the perimeter of the ellipse.

example

Examples

collapse all

Interactively place a rectangle by clicking and dragging. Use wait to block the MATLAB command line. Double-click on the rectangle to resume execution of the MATLAB command line.

imshow("pout.tif")
h = imrect;
position = wait(h)

Interactively place an ellipse by clicking and dragging. Use wait to block the MATLAB command line. Double-click on the ellipse to resume execution of the MATLAB command line.

imshow("coins.png")
h = imellipse;
position = wait(h)

Input Arguments

collapse all

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

Ellipse ROI object, specified as an imellipse object.

Output Arguments

collapse all

Position of the ROI object, returned as a numeric array. The shape of the array depends on the type of ROI object, and is consistent with the output of getPosition.

ROI ObjectReturned position
imfreehandn-by-2 matrix. The two columns define the x- and y-coordinates, respectively, of the n points along the boundary of the freehand region.
imline2-by-2 matrix of the form [x1 y1; x2 y2], representing the 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 x- and y-coordinates, respectively, of each of the n vertices.
imrect4-element vector of the form [xmin ymin width height]. The initial size of the rectangle is width-by-height pixels. The upper-left corner of the rectangle is at the (x,y) coordinate (xmin,ymin).

Vertices of ellipse ROI object, returned as an n-by-2 matrix. The two columns define the x- and y-coordinates, respectively, of each of the n vertices. The form of the matrix is consistent with the output of getVertices.

Version History

Introduced in R2008a

collapse all

R2018b: wait 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 19b, all the new ROI objects support a wait object function, as the old ROI objects did. Use the wait function to block the MATLAB command line after creating an ROI. For example, you can use wait to block the command line until you have finished positioning the ROI.

By default, the new wait function returns control to the command line after you double-click the ROI. However, using events, you can implement a custom wait function that resumes execution of the command line after several types of actions, such as clicking the ROI while pressing the Shift key or clicking a specific part of the ROI such as the label. For an example, see Use Wait Function After Drawing ROI.

Update Code

Update all instances of wait.

Discouraged UsageRecommended Replacement

This example creates a Rectangle ROI and then pauses the MATLAB command line. You can move the ROI during this pause. When you are done, double-click the mouse. Control returns to the command line and the wait function returns position information to the workspace in the variable pos.

imshow('cameraman.tif')
h = imrect(gca,[10 10 100 100]);
pos = wait(h);
% When you double-click, wait returns.
% View the value of the pos variable.
pos

To migrate use of the wait function, create the ROI using the new ROI objects. Remove the wait return value—the new wait object function does not return a value. Instead, the ROI updates the values properties changed during the pause, such as the Position property.

imshow('cameraman.tif');
h = drawrectangle(gca,'Position',[10 10 100 100]);
wait(h);
% When you double-click, control returns to the command line.
% View the value of the Position property. 
h.Position
he = drawellipse;
pos = wait(he);

The new wait object function does not support a separate syntax for obtaining the position of an Ellipse ROI. Use the wait(h) syntax instead.