File Exchange

image thumbnail

SETPOS 1.2 - GETPOS 1.2

version 1.0 (5.45 KB) by

Two flexible wrappers to manage graphics object position.

4.66667
3 Ratings

1 Download

Updated

No License

Editor's Note: This was a File Exchange Pick of the Week

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.

##################################################
Versions:

(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.

Comments and Ratings (7)

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
position_in_unit=get(h,'position');
% Test for root:
if verLessThan('matlab','8.4')
rootTest = ~href;
else
rootTest = isequal(href,groot);
end
% 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');
end
% 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;
else
rootTest = isequal(href,groot);
end
if rootTest % HREF is the Root object (no 'Position' property)

Naor Movshovitz

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

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')
href=h;
flag_href=1;
end

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

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.

Jos x@y.z

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

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.

Peter (PB) Bodin

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

Updates

Add in the description

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

MATLAB Release
MATLAB 6.1 (R12.1)

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

» Watch video