From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Error in 'pixelbounds'
Date: Thu, 3 Jan 2013 09:05:11 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 18
Message-ID: <kc3hk7$grl$>
References: <kc2kpn$e0i$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1357203911 17269 (3 Jan 2013 09:05:11 GMT)
NNTP-Posting-Date: Thu, 3 Jan 2013 09:05:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: comp.soft-sys.matlab:785848

"matt dash" wrote in message <kc2kpn$e0i$>...
> I realize it's undocumented for a reason, but i've noticed that sometimes when i'm using the opengl renderer, getting an axes pixelbounds gives an extremely wrong answer sometimes. (And then sometimes doing the exact same process it works just fine). To add to the debugging difficulty, it always gives the correct answer if there is a debug breakpoint anywhere in any mfile.
> By any chance has anyone found a line of code i could put before get(...,'pixelbounds') to ensure that it always gives correct values? Drawnow/pause don't fix it.

Hi Matt,

As I wrote in my book, PixelBounds is unreliable and quite often returns invalid data. While it is much faster than using getpixelposition, remember the adage that a wrong answer is always infinitely slower than a correct one. 

A few times over the past years I've asked MathWorks to fix PixelBounds, but instead I received a hint that they are actually planning to remove the property altogether (which has still not happened, but who knows). I'd be most happy to learn otherwise.

If you want to convert an axes graphic object to pixel position, you can use the short code within %matlabroot%/toolbox/matlab/scribe/@scribe/@scribepin/topixels.m. It also relies on undocumented properties and internal DLL functions, by the way. I described its usage recently, in my article on pinning figure annotations to an axes:

Yair Altman