You can use randperm like this, but I don't know if it will be faster than shake :
[m,n]=size(a) for c = 1:n a(randperm(m),c) = a(:,c); end
Or you can try switching randperm around to see which is faster (should give the same result):
[m,n]=size(a) for c = 1:n a(:,c) = a(randperm(m),c); end
Otherwise, how many lines do you have? If you have far fewer rows than columns, perhaps we can assume that each permutation will repeat, so something like this is something like this:
[m,n]=size(a) cols = randperm(n); k = 5; %
which would significantly reduce the number of calls to randperm . Splitting it into k sets of equal size may not be optimal, although you may want to add some randomness to them. The main idea here is that there will only be factorial(m) different orderings, and if m much less than n (for example, m=5 , n=100000 as your data), then these orderings will be repeated naturally, Therefore, instead of to allow this to happen on its own, rather control the process and reduce the number of calls to randperm , which in any case will produce the same result.
source share