Sam
Sam

Reputation: 487

Index synchronization

I have a one column which shows my distance and another column with corresponding time like below:

Y=[1;3;6;7.5;7;10;13] and t=[1;2;3;5;8;10;11]

In case of plotting, it would be easy just using below command:

plot(t,Y)

which gives me what I want, a vector of distance according to corresponding times but what if I want to use another function like findpeak on mix of my column not just over one column like Y.

Indeed I want to find the local peak in a vector which its time sequence in not completed. I have to interpolate missing data in Y at the corresponding time by NaN. Indeed my data should be Like below: Y=[1;3;6;NaN;7.5;NaN;NaN;7;NaN;10;13] and t=[1;2;3;4;5;6;7;8;9;10;11]. Firstly, how to do that, and secondly how could I find the peaks in Y vector with NaN.

I hope I well explained the problem. Thanks

Upvotes: 0

Views: 64

Answers (1)

Buck Thorn
Buck Thorn

Reputation: 5073

This is two questions (which have been answered on SO before): first question is how to interpolate within a dataset to estimate missing points. Use interp1 to interpolate missing entries:

Y=[1;3;6;NaN;7.5;NaN;NaN;7;NaN;10;13];
t=[1;2;3;4;5;6;7;8;9;10;11];

% here's where it all happens ...
ind = ~isnan(Y);
Ynew = interp1(t(ind),Y(ind),t,'cubic');

figure
plot(t,Y,'o')
hold on
plot(t,Ynew,':.')

The second question is how to find peaks. This is a more open ended question which depends on what you are looking for (are local maxima ok, what kind of thresholds are you using?). You can use findpeaks for instance:

[ypeaks ipeaks]=findpeaks(Ynew);

plot(t(ipeaks),ypeaks,'*r')

Upvotes: 1

Related Questions