Simple Interpolation with interp1
Mostra commenti meno recenti
Hi,
I'm having trouble with interp1. I have velocity recorded as a function of time. Some of the velocities were thrown out from a filtering process. I would like to go back and fill in the missing values with a linear interpolation. The input time series may only have one missing value between observations or it may have large gaps of missing values. I expect to end up with a time series with no missing values.
A cubic interpolation fills in all the gaps... interpX=interp1(time,velocity,time, 'cubic')
but this still leaves gaps interpX=interp1(time,velocity,time, 'linear')
What am I doing wrong?
Thanks,
Tim
Risposta accettata
Più risposte (2)
Andrei Bobrov
il 29 Set 2011
time = [0 sort(randi(120,1,5))]
velocity = randi(120,1,6)
t = linspace(time(1),time(end),100);
rl = interp1(time,velocity,t);
rc = interp1(time,velocity,t,'cubic');
plot([rl',rc']),grid on
ADDED
tvy = [0.595 0.2243
0.605 0.2421
0.615 NaN
0.625 NaN
0.635 0.2181
0.645 NaN
0.655 0.1911
0.665 0.2479
]
tvw = tvy(~isnan(tvy(:,2)),:)
t = sort([tvw(2:end-1,1); linspace(tvw(1,1),tvw(end,1),100)']);
rl = interp1(tvw(:,1),tvw(:,2),t);
rc = interp1(tvw(:,1),tvw(:,2),t,'cubic');
plot(t,rl,t,rc,tvw(:,1),tvw(:,2),'go'),grid on
1 Commento
Tim
il 29 Set 2011
Tim
il 29 Set 2011
0 voti
Categorie
Scopri di più su Interpolation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!