meshgrid

Construct a grid of points from coordinate vectors.

Syntax

[xx, yy] = meshgrid(x)

[xx, yy] = meshgrid(x, y)

[xx, yy, zz] = meshgrid(x)

[xx, yy, zz] = meshgrid(x, y, z)

Inputs

x, y, z
Coordinate vectors from which to construct a grid.
Type: double | integer
Dimension: scalar | vector | matrix

Outputs

xx
The matrix of the x-axis coordinates.
yy
The matrix of the y-axis coordinates.
zz
The matrix of the z-axis coordinates.

Examples

One input 2D example.

x = [1:3];
[xx yy] = meshgrid(x)
xx = [Matrix] 3 x 3
1 2 3 
1 2 3 
1 2 3 
yy = [Matrix] 3 x 3
1 1 1 
2 2 2 
3 3 3

Two input 2D example:

x = [1:3];
y = [5:8];
[xx yy] = meshgrid(x, y)
xx = [Matrix] 3 x 3
1 2 3 
1 2 3 
1 2 3 
yy = [Matrix] 4 x 3
5 5 5 
6 6 6 
7 7 7 
8 8 8 

Comments

The first argument, x, is used to construct grid coordinates along the horizontal axis, which is the second dimension in memory. Likewise, the second argument, x, is used to construct grid coordinates along the vertical axis, which is the first dimension in memory. This is the transpose of what is produced by ndgrid.

When only one input argument is present, it is used to construct grid coordinates for all output axes.