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
?
ndgrid(1:A(1), 1:A(2), 1:A(3))
). Is this what you want, withvectors = arrayfun(@(x) {1:x}, A)
? – Luis Mendongrid
gives. I checkedcombs
obtained with that code and myT
and I got different matrices. – TEX