문제

I have a matrix M of data and a matrix E of errors that I want to plot with errorbar against an independent variable x. I would also like lines between points in the same row. One column in M or E corresponds to one x-value, so this can be accomplished with

errorbar(x, M, E, 'o-')

I am missing some data points and these have the value NaN. As it should errorbar() ignores these, but the line between the points closest two points in the same row (the one resulting from the '-' option) is broken.

I have seen some different solutions that work with vectors as opposed to matrices, involving ~any(isnan(y),1) and L=~(isnan(x)|isnan(y)), but these lead to problems like

Error using errorbar
X, Y and error bars must all be the same length

I can't find a solution for matrices, any ideas?

도움이 되었습니까?

해결책

Because the missing data points are probably not the same for every line I advice to plot in a loop like this (assuming plot data are columns of the matrices):

for i = 1 : size(M, 2)
  data = M(:, i);
  good = not(isnan(data));
  xi = x(good);
  data = data(good);
  error = E(good, i);
  errorbar(xi, data, error, 'o-');
  hold on;
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top