MATLAB Answers

laurie
1

Draw uninterrupted lines on a plot with missing values

Asked by laurie
on 15 Oct 2012
Hi
I have data (Y) sorted into different columns and i want to plot it using Matlab. Each column represents one value of X and i plot the mean and standard error of each column of Y versus the value of X.
However, depending on dataset, some values of X might be missing. When this happens, I get a plot that has interrupted lines : when a "NaN" is encountered for one value of X, the line breaks/gets interrupted around the missing data instead of just "skipping over it".
How can I make it "skip over it" so that I dont have broken lines on my plots ?
Thank you

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by José-Luis
on 15 Oct 2012
Edited by José-Luis
on 15 Oct 2012
 Accepted Answer

idx = ~any(isnan(y),1);
plot(x(idx),y(idx));
Also, you could use nanmean() to get the mean in the presence of NaN's.

  0 Comments

Sign in to comment.


Answer by laurie
on 15 Oct 2012

Thanks, the "any(isnan(.." code works like a charm for :-)

  0 Comments

Sign in to comment.