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

11 views (last 30 days)
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!

Answers (2)

Star Strider
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
  3 Comments
Star Strider
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
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

Sign in to comment.


Jan
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
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.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!