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
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
![]() |
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
![]() |
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
![]() |