perms
All possible permutations
Syntax
Description
P = perms(
returns a matrix containing all permutations of the elements of vector v
)v
. 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
All Permutations of Double Integers
All Permutations of Unsigned Integers
v = uint16([1023 4095 65535]); P = perms(v)
P = 6x3 uint16 matrix
65535 4095 1023
65535 1023 4095
4095 65535 1023
4095 1023 65535
1023 65535 4095
1023 4095 65535
All Permutations of Complex Numbers
v = [1+1i 2+1i 3+1i]; P = perms(v)
P = 6×3 complex
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
v
— Set of items
vector of numeric, logical
, or char
values
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.
More About
Permutations
Permutations of a set are all possible arrangements of the
elements of the set. P = perms(v)
returns permutations of the
elements of a vector v
in reverse lexicographic order of the
element indices in v
. For example, for a vector
v
with 3 elements, P = perms(v)
returns
the same output
as:
P = [v(3) v(2) v(1); v(3) v(1) v(2); v(2) v(3) v(1); v(2) v(1) v(3); v(1) v(3) v(2); v(1) v(2) v(3)]
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
See Also
nchoosek
| permute
| randperm
| combinations
Beispiel öffnen
Sie haben eine geänderte Version dieses Beispiels. Möchten Sie dieses Beispiel mit Ihren Änderungen öffnen?
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)