www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/InterpolateScatteredDataOveraUniformGridExample.m
%% Interpolate Scattered Data Over a Uniform Grid % Copyright 2015 The MathWorks, Inc. %% % Sample a function at 200 random points between |-2.5| and |2.5|. xy = -2.5 + 5*gallery('uniformdata',[200 2],0); x = xy(:,1); y = xy(:,2); v = x.*exp(-x.^2-y.^2); %% % |x|, |y|, and |v| are vectors containing scattered (nonuniform) sample % points and data. %% % Define a regular grid and interpolate the scattered data over the grid. [xq,yq] = meshgrid(-2:.2:2, -2:.2:2); vq = griddata(x,y,v,xq,yq); %% % Plot the gridded data as a mesh and the scattered data as dots. figure mesh(xq,yq,vq); hold on plot3(x,y,v,'o'); h = gca; h.XLim = [-2.7 2.7]; h.YLim = [-2.7 2.7];