k permutation of an n-membered vector
Version 1.0.2 (1,28 KB) von
WinCento99
"perms" requires a lot of memory for vectors greater than 10 members.If you need limited permutations(k) of a vector, you can use "perms_k".
For use with permutation of 6 and vector with 3 members:
perms_k([700 2 nan],6)
The output is as follows:
ans =
700 NaN 2
2 NaN 700
700 2 NaN
NaN 2 700
NaN 700 2
2 700 NaN
If you need indexes:
[~ , index] = perms_k([700 2 nan],6)
and output is:
index =
1 3 2
1 2 3
2 3 1
3 2 1
2 1 3
3 1 2
If the amount of permutation required is greater than the factorial of the number of members:
perms_k([700 2 nan],7)
or
[~ , index] = perms_k([700 2 nan],7)
You receive an error with the following content:
# Your chosen k is greater than the number of permutations. 7 is greater of 6.
Zitieren als
WinCento99 (2024). k permutation of an n-membered vector (https://www.mathworks.com/matlabcentral/fileexchange/126769-k-permutation-of-an-n-membered-vector), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Erstellt mit
R2018b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.2 | Its dimensions were improved. |
||
1.0.1 | I added a photo :) |
||
1.0.0 |