[X,Y] =
meshgrid(x,y) returns
2-D grid coordinates based on the coordinates contained in vectors x and y. X is
a matrix where each row is a copy of x, and Y is
a matrix where each column is a copy of y. The
grid represented by the coordinates X and Y has length(y) rows
and length(x) columns.

[X,Y,Z]
= meshgrid(x,y,z) returns
3-D grid coordinates defined by the vectors x, y,
and z. The grid represented by X, Y,
and Z has size length(y)-by-length(x)-by-length(z).

Create a 2-D grid with uniformly spaced x-coordinates and y-coordinates in the interval [-2,2].

x = -2:0.25:2;
y = x;
[X,Y] = meshgrid(x);

Evaluate and plot the function $$f(x,y)=x{e}^{-{x}^{2}-{y}^{2}}$$ over the 2-D grid.

F = X.*exp(-X.^2-Y.^2);
surf(X,Y,F)

Starting in R2016b, it is not always necessary to create the grid before operating over it. For example, computing the expression $$x{e}^{-{x}^{2}-{y}^{2}}$$ implicitly expands the vectors x and y. For more information on implicit expansion, see Array vs. Matrix Operations.

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.