Reputation: 20355
Suppose I have
A = [1 2 3 nan 5];
If I do
plot(1:5, A, 'o-');
I will have the blue part as below.
How to achieve the red part?
I am sorry for not making the point straight in the first shot, but the isnan()
method that helps skip those values is not desired, because I need to plot many of those lines, some of whom have missing values (NaN
) at some random locations. So I have to keep the x-axis consistent for every line. That is why I cannot simply skip NaN
.
Upvotes: 2
Views: 9352
Reputation: 149
x = linspace(1,10,10);
y = [1 2 3 nan 5 6 7 nan 9 10];
figure, plot(x,interp1(x,y,x,'spline'))
Upvotes: 0
Reputation: 272667
Not super elegant, but functional:
idxs = ~isnan(A);
x = 1:5;
plot(x(idxs), A(idxs));
Upvotes: 11