%% 3-D Interpolation
% Create an interpolant for a set of scattered sample points, then evaluate the interpolant at a set of 3-D query points.
%
% Define 200 random points and sample a trigonometric function. These points are the sample values for the interpolant.

rng default;
P = -2.5 + 5*rand([200 3]);
v = sin(P(:,1).^2 + P(:,2).^2 + P(:,3).^2)./(P(:,1).^2+P(:,2).^2+P(:,3).^2);

%
% Create the interpolant.

F = scatteredInterpolant(P,v);

%
% Evaluate the interpolant at query locations (xq,yq,zq).

[xq,yq,zq] = meshgrid(-2:0.25:2);
vq = F(xq,yq,zq);

%
% Plot slices of the result.

xslice = [-.5,1,2]; 
yslice = [0,2]; 
zslice = [-2,0];
slice(xq,yq,zq,vq,xslice,yslice,zslice)

% Copyright 2012 The MathWorks, Inc.