Description |
COMBN - all combinations of elements
M = COMBN(V,N) returns all combinations of N elements of the elements in
vector V. M has the size (length(V).^N)-by-N.
[M,I] = COMBN(V,N) also returns the index matrix I so that M = V(I).
V can be an array of numbers, cells or strings.
Example:
M = COMBN([0 1],3) returns the 8-by-3 matrix:
0 0 0
0 0 1
0 1 0
0 1 1
...
1 1 1
All elements in V are regarded as unique, so M = COMBN([2 2],3) returns
a 8-by-3 matrix with all elements equal to 2.
NB Matrix sizes increases exponentially at rate (n^N)*N.
For larger values of n and N, one could loop over the output of COMBNSUB retrieving one or more rows of the output at a single time.
See also PERMS, NCHOOSEK
and COMBNSUB, ALLCOMB, and PERMPOS here on the FEX
Latest version 4.3 (apr 2013) |