{"id":1447,"date":"2005-11-07T09:01:37","date_gmt":"2005-11-07T14:01:37","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=1447"},"modified":"2016-05-10T09:12:41","modified_gmt":"2016-05-10T13:12:41","slug":"get-in-units","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2005\/11\/07\/get-in-units\/","title":{"rendered":"Get In Units"},"content":{"rendered":"<p>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?<\/p>\n<pre class=\"code\">hAxes = axes;\r\ncurrentUnits = get(hAxes,'Units');\r\nset(hAxes,'Units','Pixels');\r\naxesPositionPixels = get(hAxes,'Position');\r\nset(hAxes,'Units',currentUnits)\r\n<\/pre>\n<p>My code is littered with fragments like this. While it works, there are two things I don&#8217;t like about my code:<\/p>\n<ol>\n<li>3 out of 4 lines have nothing to do with getting the information I want<\/li>\n<li>It&#8217;s not the least bit obvious what my code is doing<\/li>\n<\/ol>\n<p>If I were smart, I would have figured out long ago that what I really wanted was a function that would return the property&#8217;s value in whatever units I specified. Fortunately, Jiro Doke recognized this coding pattern and developed a very convenient solution. <a title=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=8898&amp;objectType=File (link no longer works)\">getInUnits<\/a> does exactly what its name says &#8211; it allows you to GET the value of any property that depends on Units or Font Units in whatever units you specify.<\/p>\n<p>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!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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?<br \/>\nhAxes = axes;<br \/>\ncurrentUnits =&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2005\/11\/07\/get-in-units\/\">read more >><\/a><\/p>\n","protected":false},"author":33,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/1447"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=1447"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/1447\/revisions"}],"predecessor-version":[{"id":7019,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/1447\/revisions\/7019"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=1447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=1447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=1447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}