# MATLAB: Simple Interpolation with interp1

simple interpolation

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

``% Set method to 'linear' or 'cubic'method = 'linear';% Datax = [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];t = x(:,1);y = x(:,2);% Interpolation, first cutting out NaNsidx = isnan(y);y(idx) = interp1(t(~idx),y(~idx),t(idx),method)subplot(2,1,1)plot(t,y,'o-')% Interpolation on raw datay = x(:,2);y(idx) = interp1(t,y,t(idx),method)subplot(2,1,2)plot(t,y,'o-')``