nextperm

Outputs the next permutation of the ordered tuple x.
972 Downloads
Updated 12 Aug 2010

View License

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://se.mathworks.com/matlabcentral/fileexchange/22692-nextperm), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Linear Algebra in Help Center and MATLAB Answers
Version Published Release Notes
1.1.0.0

Made a small change in the description of the function.

1.0.0.0