You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
Using lexical order on the set {1, 2, ..., N}, outputs the next permutation of the ordered tuple x. You have exhausted the list when All(nextperm(x,N) == x) is TRUE.
For example
nextperm([1 5 4], 5) returns [2 1 3]
nextperm([2 1 3], 5) returns [2 1 4]
nextperm([5 4 3], 5) returns [5 4 3]
Cite As
Steven Gregory (2026). nextperm (https://uk.mathworks.com/matlabcentral/fileexchange/22692-nextperm), MATLAB Central File Exchange. Retrieved .
Acknowledgements
Inspired by: modinv(x, N), logmod
Inspired: Fast batch generation of permutations, logmod, modinv(x, N), egcd.m
General Information
- Version 1.1.0.0 (1.27 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
