Documentation

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 thepositionas 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. Ifrecursiveis true, the returned position is relative to the parent figure ofhandle

Use thegetpixelpositionfunction 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

More About

collapse all

Pixels

Distances in pixels are independent of your system resolution on Windows®andMacintoshsystems:

  • On Windows systems, a pixel is 1/96th of an inch.

  • OnMacintoshsystems, a pixel is 1/72nd of an inch.

On Linux®systems, the size of a pixel is determined by your system resolution.

Was this topic helpful?