Move figure to specified location on screen
movegui( moves the current figure or
the callback figure to the specified position. To determine the current figure or the
callback figure use
gcbf, respectively. Note that
gcbf return figures created with the
function only. If one does not exist, MATLAB® creates one using
figure and moves it to the specified
movegui moves the current figure (
gcf) or the
callback figure (
gcbf) to the closest position that puts it entirely on
Move Figure with Position Vector
Create a figure and move it so that the bottom left corner is 300 pixels from the left side of the screen and 600 pixels from the bottom.
fig = uifigure; movegui(fig,[300 600]);
Move Figure with Position Name
Create a figure and move it to the bottom center of the screen.
f = figure;
Move Current Figure
f1 = figure;
f2 = figure;
f2 moves because it is the current figure.
Move Off-Screen Figure on Screen
Create a figure that is positioned far outside the upper rightmost corner of the screen. Then, move it onscreen.
f = figure('Position',[10000 10000 400 300]);
The figure moves to the top right corner of the screen because that is the position that is closest to its last location.
f — Figure
Figure, specified as a
Figure object created with either the
uifigure function. Use this
argument to specify a figure you want to move.
position — Position
two-element numeric vector | character vector | string scalar
Position of the figure on the screen, specified as a two-element numeric vector, a character vector, or a string scalar. A numeric vector specifies x- and y-values in pixels, and a text argument specifies one of the predefined position names.
To indicate the offset of the figure from the edges of the screen in units of
pixels, specify a two-element numeric vector,
[x y]. The edge of the
screen that the offset is measured from depends on the sign of the vector
|Position Vector Element
x >= 0
|Offset of left side from left edge of screen
x < 0
|Offset of right side from right edge of screen
y >= 0
|Offset of bottom from bottom edge of screen
y < 0
|Offset of top from top edge of screen
You can also specify
position as one of these position
|Top right corner
|Top left corner
|Bottom right corner
|Bottom left corner
|Location nearest to the current location that is entirely on screen
Distances in pixels are independent of your system resolution on Windows® and Macintosh systems:
On Windows systems, MATLAB defines a pixel as 1/96th of an inch.
On Macintosh systems, MATLAB defines a pixel as 1/72nd of an inch.
On Linux® systems, your system resolution determines the size of a MATLAB pixel. For more information, see DPI-Aware Behavior in MATLAB.
Use with Maximized Figures
movegui to a maximized figure window moves the window
towards the taskbar and creates a gap on the opposite side of the screen about as wide as
the task bar. The window might shrink in size by a few pixels. If you use the
onscreen option with a maximized figure window, then
movegui creates a gap on both the left and upper sides of the screen
so that the top left corner of the figure is visible.
Introduced before R2006a