%% Evaluate Outside Domain of 3-D Function
% Create the grid vectors, x1, x2, and x3. These vectors define the points associated with the values in V.

x1 = 1:100;
x2 = (1:50)';
x3 = 1:30;

%
% Define the sample values to be a 100-by-50-by-30 random number array, V. Use the gallery function to create the array.

rng('default')
V = rand(100,50,30);

%
% Evaluate V at three points outside the domain of x1, x2, and x3. Specify extrapval = -1.

xq1 = [0 0 0];
xq2 = [0 0 51];
xq3 = [0 101 102];
vq = interpn(x1,x2,x3,V,xq1,xq2,xq3,'linear',-1)

% All three points evaluate to -1 because they are outside the domain of x1, x2, and x3.
% Copyright 2015 The MathWorks, Inc.