Documentation Center

  • Trial Software
  • Product Updates


Create 2-D rectangle object


h = rectangle(...)


For a list of properties, see Rectangle Properties.


rectangle draws a rectangle with Position [0,0,1,1] and Curvature [0,0] (i.e., no curvature).

rectangle('Position',[x,y,w,h]) draws the rectangle from the point x,y and having a width of w and a height of h. Specify values in axes data units.

Note that, to display a rectangle in the specified proportions, you need to set the axes data aspect ratio so that one unit is of equal length along both the x and y axes. You can do this with the command axis equal or daspect([1,1,1]).

rectangle('Curvature',[x,y]) specifies the curvature of the rectangle sides, enabling it to vary from a rectangle to an ellipse. The horizontal curvature x is the fraction of width of the rectangle that is curved along the top and bottom edges. The vertical curvature y is the fraction of the height of the rectangle that is curved along the left and right edges.

The values of x and y can range from 0 (no curvature) to 1 (maximum curvature). A value of [0,0] creates a rectangle with square sides. A value of [1,1] creates an ellipse. If you specify only one value for Curvature, then the same length (in axes data units) is curved along both horizontal and vertical sides. The amount of curvature is determined by the shorter dimension.

rectangle('PropertyName',propertyvalue,...) draws the rectangle using the values for the property name/property value pairs specified and default values for all other properties. For a description of the properties, see Rectangle Properties.

h = rectangle(...) returns the handle of the rectangle object created.


This example sets the data aspect ratio to [1,1,1] so that the rectangle is displayed in the specified proportions (daspect). Note that the horizontal and vertical curvature can be different. Also, note the effects of using a single value for Curvature.


Specifying a single value of [0.4] for Curvature produces

A Curvature of [1] produces a rectangle with the shortest side completely round:

This example creates an ellipse and colors the face red.


Setting Default Properties

You can set default rectangle properties on the axes, figure, and rootobject levels:


where Property is the name of the rectangle property whose default value you want to set and PropertyValue is the value you are specifying. Use set and get to access the surface properties.

More About

expand all


Rectangle objects are 2-D and can be drawn in an axes only if the view is [0 90] (i.e., view(2)). Rectangles are children of axes and are defined in coordinates of the axes data.

See Also

| | |

Was this topic helpful?