Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

combnk

Enumeration of combinations

Syntax

C = combnk(v,k)

Description

C = combnk(v,k) returns all combinations of the n elements in v taken k at a time.

C = combnk(v,k) produces a matrix C with k columns and n!/k!(nk)! 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.

Examples

Combinations of characters.

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

See Also

|

Introduced before R2006a

Was this topic helpful?