# Get In Units

How many times have you written code that looks like this, just to find the position of a graphics object in something other than its current units?

hAxes = axes;
currentUnits = get(hAxes,'Units');
set(hAxes,'Units','Pixels');
axesPositionPixels = get(hAxes,'Position');
set(hAxes,'Units',currentUnits)


My code is littered with fragments like this. While it works, there are two things I don’t like about my code:

1. 3 out of 4 lines have nothing to do with getting the information I want
2. It’s not the least bit obvious what my code is doing

If I were smart, I would have figured out long ago that what I really wanted was a function that would return the property’s value in whatever units I specified. Fortunately, Jiro Doke recognized this coding pattern and developed a very convenient solution. getInUnits does exactly what its name says – it allows you to GET the value of any property that depends on Units or Font Units in whatever units you specify.

I also want to thank Jiro for his responsiveness. I emailed him with a very small suggestion after I came across this submission. He got right back to me, and posted an updated file almost immediately. Great stuff, Jiro!

|