I am trying to interpolate the points within a dataset but to extrapolate any x values outside of the dataset range by assuming the 2 end points continue with the same y value. I am using interp1 to carry out the interpolation. However, I see that Octave or Matlab only allows extrapolation of a single scalar value. Can someone advise how I can extrapolate using 2 separate values instead?
1 Answers
0
votes
In matlab if you specify 'extrap' than it will extrapolate using the same method as interpolation, if your interpolation is not "nearest" than you can set the outside values manually:
x=[0,1,2,3];
v=[0,1,-1,5];
xq=linspace(-5,5,100);
vq = interp1(x,v,xq,'linear','extrap');
vq(xq>max(x))=v(x==max(x));
vq(xq<min(x))=v(x==min(x));
plot(x,v,'*',xq,vq)
