RECPERMS (Recursive Permutations)
RECPERMS(n,p), where n is a positive integer, and p is a valid permutation of the integers from 1 to n, returns a vector with n elements containing the next permutation of the integers from 1 to n.
If RECPERMS(n,p) is called n!-1 times recursively (i.e feeding the output vector into the function for the next step) starting with p = 1:n, then
the successive outputs span the same output from perms(1:n). The order of the permutations is, however, different from that of perms(1:n), which
uses a different algorithm.
If the input p is 1:n, the used algorithm results in the last permutation being n:-1:1. Starting with p=1:n is, however, optional. The function is
designed to wrap to the first permutation (1:n) when the last permutation (n:-1:1) is reached. This way, if any (valid) starting permutation p is
used, then recursively calling the function n!-1 times spans all possible permutations as expected.
Cite As
Khaled Hamed (2026). RECPERMS (Recursive Permutations) (https://www.mathworks.com/matlabcentral/fileexchange/13101-recperms-recursive-permutations), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
