getpixelposition
Get component position in pixels
Syntax
position = getpixelposition(handle)
position = getpixelposition(handle,recursive)
Description
position = getpixelposition(handle)
gets the position, inpixels, of the component specified byhandle
。MATLAB®returns theposition
as a four-element vector that specifies the location and size of the component: [distance from left, distance from bottom, width, height].
position = getpixelposition(handle,recursive)
gets the position as above. Ifrecursive
is true, the returned position is relative to the parent figure ofhandle
。
Use thegetpixelposition
function only to obtain coordinates for children of figures and container components (uipanels, or uibuttongroups). Results are not reliable for children of axes or other graphics objects.
Examples
This example creates a push button within a panel, and then retrieves its position, in pixels, relative to thepanel。
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]); drawnow; pos1 = getpixelposition(h1)
pos1 = 18.6000 12.6000 88.0000 23.2000
The following statement retrieves the position of the push button, in pixels, relative to thefigure。
pos1 = getpixelposition(h1,true)
pos1 = 78.6000 52.6000 88.0000 23.2000