Draw uninterrupted lines on a plot with missing values

조회 수: 16 (최근 30일)
laurie
laurie 2012년 10월 15일
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

채택된 답변

José-Luis
José-Luis 2012년 10월 15일
편집: José-Luis 2012년 10월 15일
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.

추가 답변 (1개)

laurie
laurie 2012년 10월 15일
Thanks, the "any(isnan(.." code works like a charm for :-)

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by