%% Extrapolation of 3-D Data
% This example shows how to extrapolate a well sampled 3-D gridded dataset using scatteredInterpolant. The query points lie on a planar grid that is completely outside domain.
% Create a 10-by-10-by-10 grid of sample points. The points in each dimension are in the range, [-10, 10].

[x,y,z] = ndgrid(-10:10);

%
% Sample a function, v(x,y,z), at the sample points.

v = x.^2 + y.^2 + z.^2;

%
% Create a scatteredInterpolant, specifying linear interpolation and extrapolation.

F = scatteredInterpolant(x(:),y(:),z(:),v(:),'linear','linear');

%
% Evaluate the interpolant over an x-y grid spanning the range, [-20,20] at an elevation, z = 15.

[xq,yq,zq] = ndgrid(-20:20,-20:20,15);
vq = F(xq,yq,zq);
figure
surf(xq,yq,vq)

% The extrapolation returned good results because the function is well sampled.
% Copyright 2015 The MathWorks, Inc.