Set component position in pixels
Use this function only with GUIDE, or with apps created using
setpixelposition(handle,position) sets the
position, in pixels, of the component specified by
position argument is a
four-element vector that specifies the location and
size of the component: [pixels from left, pixels from
bottom, pixels across, pixels high]. The first two
values in this vector are the number of pixels from the
left and bottom edge of the parent container. The last
two values specify the width and height of the
sets the position as above. If Boolean
recursive is true, the position
is set relative to the parent figure of
This example first creates a push button within a panel.
f = figure('Position',[300 300 300 200]); p = uipanel('Position',[.2 .2 .6 .6]); h1 = uicontrol(p,'Style','PushButton',... 'Units','normalized',... 'String','Push Button',... 'Position',[.1 .1 .5 .2]);
The example then retrieves the position of the push button and changes its position with respect to the panel.
pos1 = getpixelposition(h1); setpixelposition(h1,pos1 + [10 10 25 25]);
Distances in pixels are independent of your system resolution on Windows® and Macintosh systems:
On Windows systems, a pixel is 1/96th of an inch.
On Macintosh systems, a pixel is 1/72nd of an inch.
On Linux® systems, the size of a pixel is determined by your system resolution.