You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
P = permsk(S, K) returns all permutations of K elements taken from the set S with N elements. P will be a N!/(N-K)!-by-K array. Each row of P holds a unique permutation of K elements.
P will be of the same type as S, which can be any kind of array (numerical, char, string, struct, cell, etc.).
Example:
permsk(1:4, 2) % -> [ 1 2 ; 1 3 ; 1 4 ; 2 1 ; ...
... 3 2 ; 3 4 ; 4 1 ; 4 2 ; 4 3]
The list of permutations in the rows of P are ordered. To speed things up slightly, you can provide a third argument, like: permsk(S, K, 1), so a call to sortrows is skipped.
When K > N, P will be empty.
See also perms, nchoosek, randperm, permute.
permn, nchoose, nchoose2 (file Exchange)
Cite As
Jos (10584) (2026). permsk (https://se.mathworks.com/matlabcentral/fileexchange/71300-permsk), MATLAB Central File Exchange. Retrieved .
General Information
- Version 1.1 (1.77 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
