| MATLAB® | ![]() |
| On this page… |
|---|
The figure Position property controls the size and location of the figure window on the root screen. At startup, the MATLAB® software determines the size of your computer screen and defines a default value for Position. This default creates figures about one-quarter of the screen's size and places them centered left to right and in the top half of the screen.
MATLAB defines the figure Position property as a vector.
[left bottom width height]
left and bottom define the position of the first addressable pixel in the lower left corner of the window, specified with respect to the lower left corner of the screen. width and height define the size of the interior of the window (i.e., exclusive of the window border).

MATLAB does not measure the window border when placing the figure; the Position property defines only the internal active area of the figure window.
Because figures are windows under the control of your computer's windowing system, you can move and resize figures as you would any other windows. MATLAB automatically updates the Position property to the new values.
When a figure is docked in the MATLAB desktop, the Position property is defined with respect to the figure group container within the desktop. See Docking Figures in the Desktop for more information.
The figure's Units property determines the units of the values used to specify the position on the screen. Possible values for the Units property are
set(gcf,'Units')
[ inches | centimeters | normalized | points | {pixels} |
characters]
with pixels being the default. These choices allow you to specify the figure size and location in absolute units (such as inches) if you want the window always to be a certain size, or in units relative to the screen size (such as pixels).
Characters are units that enable you to define the location and size of the figure in units that are based on the size of the default system font. See Example — Using Figure Panels for an example that uses character units.
Whatever units you use, it is important to know the extent of the screen in those units. You can obtain this information from the root CDataMapping property. For example,
get(0,'ScreenSize')
ans =
1 1 1152 900
In this case, the screen is 1152 by 900 pixels. MATLAB returns the ScreenSize in the units determined by the root Units property. For example,
set(0,'Units','normalized')
normalizes the values returned by ScreenSize.
get(0,'ScreenSize')
ans =
0 0 1 1
Defining the figure Position in terms of the ScreenSize in normalized units makes the specification independent of variations in screen size. This is useful if you are writing an M-file that is to be used on different computer systems.
Suppose you want to define two figure windows that occupy the upper third of the computer screen (e.g., one for uicontrols and the other to display data). To position the windows precisely, you must consider the window borders when calculating the size and offsets to specify for the Position properties.
The figure Position property does not include the window borders, so this example uses a width of 5 pixels on the sides and bottom and 30 pixels on the top.
bdwidth = 5; topbdwidth = 30;
Ensure root units are pixels and get the size of the screen:
set(0,'Units','pixels') scnsize = get(0,'ScreenSize');
Define the size and location of the figures:
pos1 = [bdwidth,... 2/3*scnsize(4) + bdwidth,... scnsize(3)/2 - 2*bdwidth,... scnsize(4)/3 - (topbdwidth + bdwidth)]; pos2 = [pos1(1) + scnsize(3)/2,... pos1(2),... pos1(3),... pos1(4)];
figure('Position',pos1)
figure('Position',pos2)
The two figures now occupy the top third of the screen.

![]() | Docking Figures in the Desktop | Figure Colormaps — The Colormap Property | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |