image thumbnail


version (2.52 KB) by Matt Fig
All possible permutations of the elements of set N, taken K at a time, with repetition.


Updated 31 Aug 2012

View License

MAT = NPERMUTEK(N,K) returns all possible permutations of the elements taken from vector N of length K. This type of sampling is an ordered sample with replacement.
This is also known as the permutations with repetition.
MAT has size (length(N)^K)-by-K, where K must be a scalar.

[MAT, IDX] = NPERMUTEK(N,K) also returns IDX such that MAT = N(IDX).

If N is of class single, MAT and IDX will be also.

Please email me about bugs in the code.

Cite As

Matt Fig (2022). N_PERMUTE_K (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: permn

Inspired: VChooseKRO, n permute k

Community Treasure Hunt

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

Start Hunting!