Main Content

combntns

(Removed) All possible combinations of set of values

    The combntns function has been removed. Use the nchoosek function instead. For more information, see Version History.

    Description

    C = combntns(v,k) returns all possible combinations of the set of values v, given combinations of length k.

    example

    Examples

    collapse all

    Find all possible combinations of five numbers taken three at a time.

    v = 1:5;
    C = combntns(v,3)
    C =
    
         1     2     3
         1     2     4
         1     2     5
         1     3     4
         1     3     5
         1     4     5
         2     3     4
         2     3     5
         2     4     5
         3     4     5

    Input Arguments

    collapse all

    Set of all choices, specified as a vector.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char
    Complex Number Support: Yes

    Number of selected choices, specified as a nonnegative integer scalar. This argument can be any numeric type, but must be real.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Output Arguments

    collapse all

    All combinations of v, returned as a matrix of the same data type as v. The number of columns in C is the same as the value of k.

    Version History

    Introduced before R2006a

    expand all

    R2022b: Removed

    The combntns function has been removed. Use the nchoosek function instead. To update your code, replace instances of the combntns function with the nchoosek function.