Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Error in 'pixelbounds'

Subject: Error in 'pixelbounds'

From: matt dash

Date: 3 Jan, 2013 00:53:11

Message: 1 of 3

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.

Subject: Error in 'pixelbounds'

From: Yair Altman

Date: 3 Jan, 2013 09:05:11

Message: 2 of 3

"matt dash" wrote in message <kc2kpn$e0i$1@newscl01ah.mathworks.com>...
> 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
 

Subject: Error in 'pixelbounds'

From: matt dash

Date: 4 Jan, 2013 16:45:09

Message: 3 of 3

"Yair Altman" wrote in message <kc3hk7$grl$1@newscl01ah.mathworks.com>...
> "matt dash" wrote in message <kc2kpn$e0i$1@newscl01ah.mathworks.com>...
> > 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!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us