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.

perms

All possible permutations

Syntax

Description

example

P = perms(v) returns a matrix containing all permutations of the elements of vector v in reverse lexicographic order. Each row of P contains a different permutation of the n elements in v. Matrix P has the same data type as v, and it has n! rows and n columns.

Examples

collapse all

v = [2 4 6];
P = perms(v)
P =

     6     4     2
     6     2     4
     4     6     2
     4     2     6
     2     6     4
     2     4     6

v = uint16([1023 4095 65535]);
P = perms(v)
P =

  6×3 uint16 matrix

   65535    4095    1023
   65535    1023    4095
    4095   65535    1023
    4095    1023   65535
    1023   65535    4095
    1023    4095   65535

v = [1+1i 2+1i 3+1i];
P = perms(v)
P =

   3.0000 + 1.0000i   2.0000 + 1.0000i   1.0000 + 1.0000i
   3.0000 + 1.0000i   1.0000 + 1.0000i   2.0000 + 1.0000i
   2.0000 + 1.0000i   3.0000 + 1.0000i   1.0000 + 1.0000i
   2.0000 + 1.0000i   1.0000 + 1.0000i   3.0000 + 1.0000i
   1.0000 + 1.0000i   3.0000 + 1.0000i   2.0000 + 1.0000i
   1.0000 + 1.0000i   2.0000 + 1.0000i   3.0000 + 1.0000i

Input Arguments

collapse all

Set of items, specified as a vector of numeric, logical, or char values.

Example: [1 2 3 4]

Example: [1+1i 2+1i 3+1i 4+1i]

Example: int16([1 2 3 4])

Example: ['abcd']

Example: [true false true false]

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

Limitations

perms(v) is practical when length(v) is less than about 10.

See Also

| |

Introduced before R2006a

Was this topic helpful?