MATLAB: How to interpolate the NaNs in the middle part of a curve

extrapolationinterpolation

Hi everyone, I am wondering how to interpolate the NaNs in the middle part of a curve? Like the plot below:
x=1:200;
Can anyone offer a hint? And besides, how to do extrapolation in matlab? Thanks a lot!

Best Answer

e.g.
a = 1:20;
b = rand(1,20);
b(4:7) = NaN;
newB = interp1( a( ~isnan(b) ), b( ~isnan(b) ), a );
also includes an extrapolation argument that you can read about on the help page:
doc interp1