ZI = griddata(x,y,z,XI,YI)[XI,YI,ZI] = griddata(x,y,z,XI,YI)
ZI = griddata(x,y,z,XI,YI) returns matrix ZI containing elements corresponding to the elements of matrices XI and YI and determined by interpolation within the two-dimensional function described by the (usually) nonuniformly spaced vectors x, y, and z.
XI can be a row vector, in which case it specifies a matrix with constant columns. Similarly, YI can be a column vector and it specifies a matrix with constant rows. [XI,YI,ZI] = griddata(x,y,z,XI,YI) returns the XI and YI formed this way, which are the same as the matrices returned by meshgrid.
griddata uses an inverse distance method.
rand('seed',0)x = rand(100,1)*4-2;y = rand(100,1)*4-2;z = x.*exp(-x.^2-y.^2);
x, y, and z are now vectors containing nonuniformly sampled data. Define a regular grid, and grid the data to it:
Plot the gridded data along with the nonuniform data points used to generate it:ti = -2:.25:2;[XI,YI] = meshgrid(ti,ti);ZI = griddata(x,y,z,XI,YI);
mesh(XI,YI,ZI)holdplot3(x,y,z,'o')hold off
See Alsointerp1,interp2
(c) Copyright 1994 by The MathWorks, Inc.