This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Use Wait Function After Drawing ROI

This example shows how to define a custom wait function that blocks the MATLAB® command line until you finish positioning a rectangle.

Display an image.


Draw a rectangle ROI in the top left corner of the image.

h = drawrectangle('Position',[1 1 100 100]);

Use a custom wait function to block the MATLAB command line while you interact with the rectangle. This example specifies a function called customWait (defined at the end of the example).

While the command line is blocked, resize and reposition the rectangle so that it encompasses one pear. Double-click on the rectangle to resume execution of the customWait function. The function returns the final position of the rectangle.

pos = customWait(h)

pos = 1×4

  262.0000   36.0000  144.0000  145.0000

This is the custom wait function that blocks the program execution when you click an ROI. When you have finished interacting with the ROI, the function returns the position of the ROI.

function pos = customWait(hROI)

% Listen for mouse clicks on the ROI
l = addlistener(hROI,'ROIClicked',@clickCallback);

% Block program execution

% Remove listener

% Return the current position
pos = hROI.Position;


This click callback function resumes program execution when you double-click the ROI. Note that event data is passed to the callback function as an images.roi.ROIClickedEventData object, which enables you to define callback functions that respond to different types of actions. For example, you could define a callback function to resume program execution when you click the ROI while pressing the Shift key or when you click a specific part of the ROI such as the label.

function clickCallback(~,evt)

if strcmp(evt.SelectionType,'double')


See Also

| | | |

Related Topics