%% Fit a Hypersurface
% Interpolate a 4-D scattered data set and visualize a 3-D isosurface of the interpolated data.
% Create a scattered set of sample points.

rng('default')
X = 2*rand([5000 3])-1;
Y = sum(X.^2,2);

%
% Create x, y, and z grids to use as the 3-D set of query points, and interpolate the scattered data at these points.

d = -0.8:0.05:0.8;
[y0,x0,z0] = ndgrid(d,d,d);
XI = [x0(:) y0(:) z0(:)];
YI = griddatan(X,Y,XI);

%
% Since it is difficult to visualize 4-D data sets, use isosurface at 0.8 to visualize the interpolation result.

YI = reshape(YI, size(x0));
p = patch(isosurface(x0,y0,z0,YI,0.8));
isonormals(x0,y0,z0,YI,p)
p.FaceColor = 'blue';
p.EdgeColor = 'none';
view(3)
axis equal
camlight
lighting phong

% Copyright 2015 The MathWorks, Inc.