Statistics Toolbox | ![]() ![]() |
Enumeration of all combinations of n objects k at a time.
Syntax
C = combnk(v,k)
Description
returns all combinations of the n elements in C = combnk(v,k)
v
taken k
at a time.
produces a matrix C = combnk(v,k)
C
with k
columns and n! / k!(n-k)! rows, where each row contains k
of the elements in the vector v
.
It is not practical to use this function if v
has more than about 15 elements.
Example
Combinations of characters from a string.
C = combnk('tendril',4); last5 = C(31:35,:) last5 = tedr tenl teni tenr tend
Combinations of elements from a numeric vector.
c = combnk(1:4,2) c = 3 4 2 4 2 3 1 4 1 3 1 2
![]() | clusterdata | cophenet | ![]() |