Matlab won't plot a range of very small numbers.

20 views (last 30 days)
4st4rl04 on 16 Mar 2015
Commented: James Tursa on 16 Mar 2015
I am having trouble plotting some values in MATLAB (R2014a on a Mac). I really don't know what the problem is. Consider the following sequence of plots:
plot((1:3),[1e-150*0.2 0 0]);
plot((1:3),[1e-151*0.2 0 0]);
plot((1:3),[1e-152*0.2 0 0]);
plot((1:3),[1e-153*0.2 0 0]);
plot((1:3),[1e-154*0.2 0 0]);
For some reason MATLAB won't plot the ones with 1e-151/153. Anyone has an idea of why this can be?
Thanks!

Star Strider on 16 Mar 2015
Use the hold function.
Try this:
figure(1)
plot((1:3),[1e-150*0.2 0 0]);
hold on
plot((1:3),[1e-151*0.2 0 0]);
plot((1:3),[1e-152*0.2 0 0]);
plot((1:3),[1e-153*0.2 0 0]);
plot((1:3),[1e-154*0.2 0 0]);
hold off

4st4rl04 on 16 Mar 2015
Hi, it is not about plotting them in the same figure. The sequence was just to show that MATLAB will plot the first and the last ones, but not the ones in between (one at a time). Thanks though.
Star Strider on 16 Mar 2015
The plot function plots to the open figure window, erasing any previous plots to it unless you use the hold function. When I ran my code (with hold in R2014b) it plotted all of them.
Similarly, this plots them all:
figure(1)
plot((1:3),[1e-150*0.2 0 0]);
figure(2)
plot((1:3),[1e-151*0.2 0 0]);
figure(3)
plot((1:3),[1e-152*0.2 0 0]);
figure(4)
plot((1:3),[1e-153*0.2 0 0]);
figure(5)
plot((1:3),[1e-154*0.2 0 0]);
James Tursa on 16 Mar 2015
Going back a few versions on my machine:
Windows 32-bit
R2009a: Plots all of them
R2013a: Plots all of them
R2014a: Plots all of them
Windows 64-bit
R2010a: Does not plot all of them
R2013a: Does not plot all of them
R2013b: Does not plot all of them
R2014a: Does not plot all of them
R2014b: Plots all of them

Jan on 16 Mar 2015
It might depend on the renderer. As far as I remember OpenGL draws with a single precision only, such that the Painters or ZBuffer renderer might work. Or the other way around?

1 Comment

4st4rl04 on 16 Mar 2015
I see. But why would it work with 1e-150 and 1e-154 and not with 1e-152? The non-monotonicty is what puzzles me. Thanks.