drawrectangle draws rectangle even though the mouse is clicked outside the parent UIAxes
Show older comments
I have a small app designed using the App Designer. Matlab 2021b
The UI is constructed of Figure->UIAxes only and the UIAxes is much smaller from the Figure.
This is the code of thestartup function.
startupFcn(app)
imshow('peppers.png', 'Parent', app.UIAxes);
h = drawrectangle(app.UIAxes)
end
There are two issues:
- While clicking the mouse outside the UIAxes and dragging , the app draws a line (i.e. rectangle with no width) on the UIAxes but outside the image. See attached.
- The rectangle can be drawn in the UIAxes but outside the image.See attached.
While using imrect(app.UIAxes) instead, the rectangle can be drawn on the image only. Mouse events outside the image are ignored.
How can I make the drawrectangle work as the imrect? (creating rectangle by clicking on the image only)
Accepted Answer
More Answers (1)
You can fall back to imrect, if necessary
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));
h=imrect('PositionConstraintFcn',fcn)
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!