Function Reference
— Function File: zi = griddata (x, y, z, xi, yi, method)
— Function File: [xi, yi, zi] = griddata (x, y, z, xi, yi, method)

Generate a regular mesh from irregular data using interpolation. The function is defined by z = f (x, y). The interpolation points are all (xi, yi). If xi, yi are vectors then they are made into a 2D mesh.

The interpolation method can be "nearest", "cubic" or "linear". If method is omitted it defaults to "linear".

See also: delaunay

Demonstration 1

The following code

 x=2*rand(100,1)-1;
 y=2*rand(size(x))-1;
 z=sin(2*(x.^2+y.^2));
 [xx,yy]=meshgrid(linspace(-1,1,32));
 griddata(x,y,z,xx,yy);
 title('nonuniform grid sampled at 100 points');

Produces the following figure

Demonstration 2

The following code

 x=2*rand(1000,1)-1;
 y=2*rand(size(x))-1;
 z=sin(2*(x.^2+y.^2));
 [xx,yy]=meshgrid(linspace(-1,1,32));
 griddata(x,y,z,xx,yy);
 title('nonuniform grid sampled at 1000 points');

Produces the following figure

Demonstration 3

The following code

 x=2*rand(1000,1)-1;
 y=2*rand(size(x))-1;
 z=sin(2*(x.^2+y.^2));
 [xx,yy]=meshgrid(linspace(-1,1,32));
 griddata(x,y,z,xx,yy,'nearest');
 title('nonuniform grid sampled at 1000 points with nearest neighbor');

Produces the following figure