MATLAB Functions | Help Desk |
rbbox
Rubberband box for area selectionrbbox
rbbox(initialRect)
rbbox(initialRect,fixedPoint)
rbbox(initialRect,fixedPoint,stepSize) finalRect = rbbox(...)
rbbox
initializes and tracks a rubberband box in the current Figure. It sets the initial rectangular size of the box to 0, anchors the box at the Figure's CurrentPoint
, and begins tracking at the Figure's CurrentPoint
.
rbbox(initialRect)
specifies the initial location and size of the rubberband box as [x y width height]
, where x
and y
define the lower-left corner, and width
and height
define the size. initialRect
is in the units specified by the current Figure's Units
property, and measured from the lower-left corner of the Figure window. The corner of the box closest to the pointer position follows the pointer until rbbox
receives a button-up event.
rbbox(initialRect,fixedPoint)
specifies the corner of the box that remains fixed. All arguments are in the units specified by the current Figure's Units
property, and measured from the lower-left corner of the Figure window. fixedPoint
is a two-element vector, [x y]
. The tracking point is the corner diametrically opposite the anchored corner defined by fixedPoint
.
rbbox(initialRect,fixedPoint,stepSize)
specifies how frequently the rubberband box is updated. When the tracking point exceeds stepSize
Figure units, rbbox
redraws the rubberband box. The default stepsize is 1
.
finalRect = rbbox(...)
returns a four-element vector, [x y width height]
, where x
and y
are the x and y components of the lower-left corner of the box, and width
and height
are the dimensions of the box.
rbbox
is useful for defining and resizing a rectangular region:
initialRect
is [x y 0 0]
, where (x,y)
is the Figure's CurrentPoint
.
initialRect
defines the rectangular region that you resize (e.g., a legend). fixedPoint
is the corner diametrically opposite the tracking point.
rbbox
returns immediately if a button is not currently pressed. Therefore, you use rbbox
with waitforbuttonpress
so that the mouse button is down when rbbox
is called. rbbox
returns when you release the mouse button.
Assuming the current view is view(2)
, use the current Axes' CurrentPoint
property to determine the extent of the rectangle in dataspace units:
k = waitforbuttonpress point1 = get(gca,'CurrentPoint')% button down detected finalRect = rbbox % return Figure units point2 = get(gca,'CurrentPoint')% button up detected point1 = point1(1,1:2)% extract x and y point2 = point2(1,1:2) p1 = min(point1,point2)% calculate locations offset = abs(point1-point2)% and dimensions x = [p1(1) p1(1)+offset(1) p1(1)+offset(1) p1(1) p1(1)] y = [p1(2) p1(2) p1(2)+offset(2) p1(2)+offset(2) p1(2)] hold on axis manual plot(x,y)% redraw in dataspace units
dragrect
, waitforbuttonpress