No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.7 | 3 ratings Rate this file 4 Downloads (last 30 days) File Size: 5.45 KB File ID: #13927 Version: 1.0
image thumbnail



Jerome Briot (view profile)


12 Feb 2007 (Updated )

Two flexible wrappers to manage graphics object position.

Editor's Notes:

This was a File Exchange Pick of the Week

| Watch this File

File Information

SETPOS/GETPOS are two flexible wrappers to set/get the "Position" property of graphics objects (figure, axes, uicontrol).

SETPOS(H,POS) works as SET(H,'Position',POS) and GETPOS(H) works as GET(H,'Position') but :

Both can set/get data using different unit for each element of the 'Position' vector.

Both can manage each element [Left,Bottom,Width,Height] individually without the others.

Both can use any graphics object HREF as position reference, instead of the parent of H. (Added in V1.1)

SETPOS contains a +/- feature that increase/decrease the corresponding value in the 'Position' vector.

Please contact me directly by email for bug report or enhancement request.


 (Both) 1.0 (12-Feb-2007)

 (Both) 1.1 (14-Feb-2007)
 Third input argument HREF added.
 Minor corrections in the help section.

 (Both) 1.2 (21-Feb-2007)
 Bug fixed if HREF is the Root object.
 Examples removed from the help section.
 Third file containing examples added.


Getinunits inspired this file.

This file inspired Rosin Rammler Diagram Plotting Tool, Legendflex.M: A More Flexible, Customizable Legend, and Ecopath Matlab: A Matlab Implementation Of Ecopath.

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
06 Apr 2015 Dan K

Dan K (view profile)

Naor: I've made it work with some minor tweaks, in both cases near line 159. In SetPos:

% Get the current "Position" vector of H
% Test for root:
if verLessThan('matlab','8.4')
rootTest = ~href;
rootTest = isequal(href,groot);
% Get the current "Position" vector of HREF
if rootTest % HREF is the Root object (no 'Position' property)
position_ref_unit=get(href,'screensize'); %%% Should be safe here !
else position_ref_unit=get(href,'position');
% if any(~flag) % No "+" or "-"
if (~flag(n)) % No "+" or "-"

In GetPos:

% Get the current "Position" vector of HREF
% Test for root:
if verLessThan('matlab','8.4')
rootTest = ~href;
rootTest = isequal(href,groot);
if rootTest % HREF is the Root object (no 'Position' property)

Comment only
04 Apr 2015 Naor Movshovitz

Really nice utility for MATLAB releases up to 2014a. Hopefully an update that works in HG2 (R2014b+) is in the works?

12 Apr 2013 Jim

Jim (view profile)

(This comment and the one following both apply to the getpos function only.)

In the fragment:

% Don't use HREF position if it is the parent of H
if href~=get(h,'parent')

the line "href=h;" appears erroneous. After removal, the function works as I expected it to.

Comment only
11 Apr 2013 Jim

Jim (view profile)

Very nicely done. Unfortunately I think there's an issue when finding positions relative to reference object. The line:

pos(n) = temp(n) - temp_href(n) * flag_href;

is correct for n = 1 or 2 (left & bottom elements of the position vector), but doesn't seem to make sense for n = 3 or 4 (width and height). Stating an object's position relative to a non-parent reference object should only affect location, not size, when working with absolute units (or "nz" if we assume everything's normalized to the same figure). And if the intent was to return object height & width relative to a reference object (for normalized units), the above line isn't the correct way to find them.

Comment only
22 Feb 2007 Jos x@y.z

I have to take back my comment about the naming conflict: setpos is a private function of the SP toolbox.

Comment only
17 Feb 2007 Jos x@y.z

Quite usefull. Well done. Good help, albeit what long.
There is a possible name class with setpos in the signal toolbox.

12 Feb 2007 Peter (PB) Bodin

Very useful utility. H1-line, error checking, cleanly written and well commented code. Well done.

15 Feb 2007

Third input argument HREF added.
Some minor corrections in the help section

16 Feb 2007

Add in the description

Contact us