%% 2-D Extrapolation
% Query an interpolant at a single point outside the convex hull using nearest neighbor extrapolation.
% Define a matrix of 200 random points and sample an exponential function. These points are the sample values for the interpolant.

rng('default')
P = -2.5 + 5*rand([200 2]);
x = P(:,1);
y = P(:,2);
v = x.*exp(-x.^2-y.^2);

%
% Create the interpolant, specifying linear interpolation and nearest neighbor extrapolation.

F = scatteredInterpolant(P,v,'linear','nearest')

%
% Evaluate the interpolant outside the convex hull.

vq = F(3.0,-1.5)

%
% Disable extrapolation and evaluate F at the same point.

F.ExtrapolationMethod = 'none';
vq = F(3.0,-1.5)

% Copyright 2015 The MathWorks, Inc.