I would like to obtain all the permutations with replacement of d elements chosen in a set of n elements (which are numbers from 0 to n-1) in MATLAB. I noticed that on MATLAB Central the method npermutek is available, but I would like to try another implementation.
My idea is to make d for loops, one inside the other, each varying an index from 0 to n-1: i.e., d recursions over a line (from 0 to n-1). However, n and d should be parameters of my code, so I cannot implement my idea of d for loops one inside the other… or could I? Do you have any suggestions?
Thank you for your attention.
I’d suggest you use
combnon the File Exchange.