Plotting a graph in MATLAB with $y$-axis data varies over order from $10^0$ to $10^{-1009}$

301 Views Asked by At

I want to plot a graph in MATLAB with $x$- axis data varies from $1$ to $15$, where as $y$-axis data varies over order from $10^0$ to $10^{-1009}$. Using 'semilog' or 'set axis I am not able to plot graph for $y$-axis data having order lower that $10^{-150}$. I am getting following error

Error using set
Bad property value found.
Object Name :  axes
Property Name : 'YLim'
Values must be increasing and non-NaN.

Here is my MATLAB code

count = 1:15;
subplot(2, 2, 1)

SAcE = [0.2548 0.18759 0.075788  0.0050042 1.4406e-6  3.437e-17  4.6674e-49 1.1689e-144  7.4999e-358 1.5437e-784  3.9277e-1009  5.0621e-1009 3.6067e-1009 5.0621e-1009 3.6067e-1009];

semilogy(count,SAcE, '-b*','LineWidth',1.0, 'MarkerSize',5, 'MarkerEdgeColor','b')

axis([1 15 1 10^(-1009) ])

Thank you for the help.

1

There are 1 best solutions below

0
On BEST ANSWER

If you take a look at the array you are plotting, you will likely see something like this:

SAcE =

  Columns 1 through 13

0.2548    0.1876    0.0758    0.0050    0.0000    0.0000    0.0000    0.0000         0         0         0         0         0

  Columns 14 through 15

     0         0

This indicates that MATLAB is not able to represent values as small as you require, see for example this question and answers for more information. Instead the very small values are rounded to zero.

I suggest that you do a workaround where you 1) represent your values in MATLAB with larger values (possibly scaled versions of your current ones) that are distinguishable from zero and 2) in your plot, write a custom y-label that shows the correct values of the data. Below is an example for synthetic data:

count = 1:5;
really_small_numbers_scaled = exp(exp(-(1:5)));

figure;
ah = axes;
semilogy(count, really_small_numbers_scaled)
yt = get(ah, 'YTick'); % the locations of ticks at y-axis corresponding to really_small_numbers_scaled
ytl = get(ah,'YTickLabel'); % the strings that MATLAB actually shows at the y-axis values corresponding to yt

% Set custom YTick and YTickLabel
yt_new = [1.1 1.2 1.25 1.4];
ytl_new = {'1.1e-10000'; '1.2e-9000'; '1.3e-8000'; '1.45e-5000'; '1.6e-1000'};
set(ah, 'YTick', yt_new, 'YTickLabel', ytl_new);