I would like to enumerate grid points in a N x m
matrix, where N
is the number of grid points and m
is the number of dimensions in the grid. For a 2D grid (i.e., m=2
), this I can accomplish this with:
a = -1:1;
b = -2:2;
[A,B] = meshgrid(a,b);
c=cat(2,A',B');
d=reshape(c,[],2);
d
where d
is a 15 x 2
matrix.
How do I to this in higher dimensions after generating the grid points with ndgrid
? For example:
[A, B, C] = ndgrid(-1:1, -2:2, 0:3);
In this example, I want to convert the elements of A,B,C
to a 60 x 3
matrix.