Consider a Matlab vector A of size 1xL, reporting some strictly positive integers. I want to construct a matrix T of size prod(A,2)xL reporting all the possible L-tuples from 1:1:A(1), 1:1:A(2), ..., 1:1:A(L).
For example, take L=3 and A=[2 3 1]. Then T can be constructed as
[ca, cb, cc] = ndgrid(1:1:A(1), 1:1:A(2), 1:1:A(3));
T= [ca(:), cb(:), cc(:)];
How can I generalise the code above to a generic L?