griddata

Purpose

Grid scattered data.

Synopsis

ZI = griddata(x,y,z,XI,YI)
[XI,YI,ZI] = griddata(x,y,z,XI,YI)

Description

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.

Examples

Sample a function at 100 random points between ±2.0:

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:

ti = -2:.25:2; 
[XI,YI] = meshgrid(ti,ti);
ZI = griddata(x,y,z,XI,YI);
Plot the gridded data along with the nonuniform data points used to generate it:

mesh(XI,YI,ZI)
hold
plot3(x,y,z,'o')
hold off
          

See Also

interp1, interp2 

(c) Copyright 1994 by The MathWorks, Inc.