Can't say I'm convinced this is quicker than just generating all the permutations with perms and post selecting, calling very quick functions recursively in Matlab is not efficient at all really.
If you just want just ONE permutation it is obviously faster and not having to store them in memory is probably nice.
There is one thing I am however confused about, which is why you have made this work only for integers, there is nothing in the logic that would mean it shouldn't work fine for double precision numbers why not let the function use the same class as the input?
Can't say I'm convinced this is quicker than just generating all the permutations with perms and post selecting, calling very quick functions recursively in Matlab is not efficient at all really.
If you just want just ONE permutation it is obviously faster and not having to store them in memory is probably nice.
There is one thing I am however confused about, which is why you have made this work only for integers, there is nothing in the logic that would mean it shouldn't work fine for double precision numbers why not let the function use the same class as the input?