%% griddedInterpolant in Two Dimensions
% This example shows how to create and plot a 2-D interpolant using griddedInterpolant.
% In two dimensions and higher, you can specify the sample coordinates as an ndgrid, a compact grid, or a default grid. In this example, we'll supply an ndgrid.
%
% Create a coarse grid and sample values.

[X,Y] = ndgrid(-1:.3:1,-2:.3:2);
V = 0.75*Y.^3 - 3*Y - 2*X.^2;

%
% Construct the griddedInterpolant.

F = griddedInterpolant(X,Y,V,'spline');

%
% Interpolate over finer intervals with 0.1 spacing.

[Xq,Yq] = ndgrid(-1:.1:1,-2:.1:2);
Vq = F(Xq,Yq);

%
% Plot the result.

figure()
surf(X,Y,V);
view(65,60)
title('Sample Data');

figure()
surf(Xq,Yq,Vq);
view(65,60)
title('Refined with Spline');

% Copyright 2015 The MathWorks, Inc.