Syntax

Arguments

x, y, z, ...

vectors of any data types. They may have distinct data types. By default, y=x.

X, Y, Z, ...

matrices in case of 2 input arguments, or hypermatrices otherwise. They all have the same sizes: size(x,"*") rows, size(y,"*") columns, size(z,"*") layers, etc. They have the datatypes of respective input vectors: typeof(X)==typeof(x), typeof(Y)==typeof(y), etc.

Description

The first application of ndgrid is to build a grid of nodes meshing the 2D or 3D or N-D space according to 2, 3, or more sets x, y, etc.. of "template" coordinates sampled along each direction/dimension of the space that you want to mesh.

Hence, the matrix or hypermatrix X is made by replicating the vector x as all its columns ; the matrix or hypermatrix Y is made by replicating the vector y as all its rows ; Z is made of replicating the vector z along all its local thicknesses (3rd dimension); etc.

Then, the coordinates of the node(i,j) in the 2D space will be simply [x(i), y(j)] now given by [X(i,j), Y(i,j)]. As well, the coordinates of a node(i,j,k) of a 3D grid will be [x(i), y(j), z(k)] now given by [X(i,j,k), Y(i,j,k), Z(i,j,k)].

This replication scheme can be generalized to any number of dimensions, as well to any type of uniform data. Let's for instance consider 2 attributes:

The first is a number, to be chosen from the vector say n= [ 3 7 ]

The second is a letter, to be chosen from the vector say c= ["a" "e" "i" "o" "u" "y"]

Then we want to build the set of all {n,c} possible pairs. It will just be the 2D grid: