Skip to content

nchoosek

specfun · scripts/specfun/nchoosek.m

: c = nchoosek (n, k)
: c = nchoosek (v, k)

Binomial coefficient or list of combinations.

If n is a non-negative integer scalar, return the binomial coefficient n!/(k!(n-k)!). The value is computed exactly while it fits in 64 bits. A warning is issued if a floating point result exceeds the largest exactly representable integer, or if an integer-class result saturates.

If v is a vector, return all combinations of its elements taken k at a time, one combination per row, in lexicographic order of element position. The class of v is preserved, so character vectors, cell arrays, logical and integer vectors are supported.