%% 1-D Extrapolation
% Compare results of querying the interpolant outside the domain of F using the 'pchip' and 'nearest' extrapolation methods.
% Create the interpolant, specifying 'pchip' as the interpolation method and 'nearest' as the extrapolation method.

x = [1 2 3 4 5];
v = [12 16 31 10 6];
F = griddedInterpolant(x,v,'pchip','nearest')

%
% Query the interpolant, and include points outside the domain of F.

xq = 0:0.1:6;
vq = F(xq);
figure
plot(x,v,'o',xq,vq,'-b');
legend ('v','vq')

%
% Query the interpolant at the same points again, this time using the pchip extrapolation method.

F.ExtrapolationMethod = 'pchip';
figure
vq = F(xq);
plot(x,v,'o',xq,vq,'-b');
legend ('v','vq')

% Copyright 2015 The MathWorks, Inc.