Code covered by the BSD License  

Highlights from
GETINUNITS

5.0

5.0 | 1 rating Rate this file 6 Downloads (last 30 days) File Size: 2.16 KB File ID: #8898

GETINUNITS

by Jiro Doke

 

01 Nov 2005 (Updated 02 Nov 2010)

Get object properties in specified units without changing the Units property.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information
Description

Have you ever created an object for your GUI using Normalized units, but wanted to get its position in Points to line up a text object according to the font size? Instead of SETting the Units property to Points, GETting the Position, and SETting the Units back to Normalized, just use getInUnits.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GETINUNITS Get object properties in specified units

V = GETINUNITS(H, PROP, UNITS) returns the object property in the specified UNITS. It will leave the 'Units' and 'FontUnits' property unchanged afterwards.

H is the handle of the object. If it is an M-element array of handles, the function will return an M-by-1 cell array. PROP can be a string or a cell array of strings. If it is a 1-by-N or N-by-1 cell array, the function will return an M-by-N cell array of values. UNITS can be a string or a cell array. If it is a cell array, then PROP must also be a cell array with the same size as UNITS, and each cell element of UNITS corresponds to a cell element of PROP.
 
V = GETINUNITS(H, PROP) is the same as GET(H, PROP)
 
Examples:
  V = GETINUNITS(H, 'Position', 'Pixels')
  V = GETINUNITS(H, {'FontSize', 'Position'}, 'Normalized')
  V = GETINUNITS(H, {'FontSize', 'Position'}, {'Points', 'Pixels'})

Acknowledgements
This submission has inspired the following:
SETPOS 1.2 - GETPOS 1.2
MATLAB release MATLAB 7.0.4 (R14SP2)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
03 Nov 2005 Jiro Doke

There's a bug that gives an error with Figure objects. A fixed version should be up soon.

05 Dec 2005 Mohammad Rahmani  
Please login to add a comment or rating.
Updates
03 Nov 2005

Fixes a bug that gives an error with Figures. I basically included a try..catch to check if FontUnits and Units properties exist or not.

02 Nov 2010

License update.

Tag Activity for this File
Tag Applied By Date/Time
development environment Jiro Doke 22 Oct 2008 08:05:14
object properties Jiro Doke 22 Oct 2008 08:05:14
units Jiro Doke 22 Oct 2008 08:05:14

Contact us at files@mathworks.com