I have the following problem. I need to compute the permutations of a set; however, the set may contain two elements which are the same and therefore cause repeated permuta
It would appear this is a regularly occurring problem. Here is a file by John d'Errico (uniqueperms
) that seems to tackle it pretty effectively. As an alternative, there is another FEX submission here by Ged Ridgway; you'll have to profile a bit to see which one is faster.
Note that due to the limitations of Matlab's JIT, loops are not accelerated if they call non-builtin functions, so it might be beneficial to copy-paste the contents of these functions (and/or specialize them a bit) inside your loop(s).