k permutation of an n-membered vector

Version 1.0.2 (1.28 KB) by 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".
5 Downloads
Updated 24 Mar 2023

View License

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.

Cite As

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. Retrieved .

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.2

Its dimensions were improved.

1.0.1

I added a photo :)

1.0.0