matlab - Is there any way to obtain different shuffled in randperm? -


i have matrix [1 2 3 4] , want shuffle randperm in few times want obtain different matrices. example

for i=1:4         m(i,:)=randperm(4);  end 

will give me 4 rows 4 columns want every row different every other one; e.g. this:

m(1,:)=[1 3 4 2] m(2,:)=[2 3 1 4] m(3,:)=[2 1 4 3] m(4,:)=[4 3 2 3] 

you can check existing rows see if current permutation exists

m = zeros(4, 4);  counter = 1;  while counter < 4     new = randperm(4);      if ~ismember(new, m, 'rows')         m(counter, :) = new;         counter = counter + 1;     end end 

another (memory intensive) approach generate all permutations , randomly select n of them

allperms = perms(1:4); n = 4;  m = allperms(randsample(size(allperms,1), n), :); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -