"Yair Altman" wrote in message <email@example.com>... > "matt dash" wrote in message <firstname.lastname@example.org>... > > 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: > http://UndocumentedMatlab.com/blog/pinning-annotations-to-graphs/ > > Yair Altman > http://UndocumentedMatlab.com >
Thanks for the info, Yair. I have your book but I didnt have it with me when i ran into this problem!