www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/TwoDimensionalScatteredInterpolationExample.m

    %% 2-D Interpolation  

% Copyright 2015 The MathWorks, Inc.


%% 
% Define 200 random points. 
xy = -2.5 + 5*gallery('uniformdata',[200 2],0);
x = xy(:,1);
y = xy(:,2);  

%% 
% Sample an exponential function. These are the sample values for the interpolant. 
v = x.*exp(-x.^2-y.^2);  

%% 
% Create the interpolant. 
F = scatteredInterpolant(x,y,v);  

%% 
% Evaluate the interpolant at query locations ($xq$, $yq$). 
ti = -2:.25:2;
[xq,yq] = meshgrid(ti,ti);
vq = F(xq,yq);  

%% 
% Plot the result. 
figure
mesh(xq,yq,vq); 
hold on; 
plot3(x,y,v,'o'); 
hold off;