randomly shuffle the matrix by taking two rows
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
For example, if I have 
     1     5     9    13    17     20
     2     6    10    14    18    21   
     3     7    11    15    19    22
     4     8    12    16    20    23
I want to have a function that can shuffle the columns around while keeping the values in the column the same. I want it done by taking two columns together.For example:
 9      13    17     20      1     5
10    14    18      21      2     6
11    15    19      22      3     7 
12    16    20     23       4     8 
In other words, the first two columns were taken together, the next two columns were taken together and randomly mixed in that way.
(Note : My matrix is normally a very large matrix. That's why I wanted to do it with code)
Can you help me to code this?
Thank you.
0 Commenti
Risposta accettata
  Voss
      
      
 il 21 Mar 2022
        A = [1     5     9    13    17    20
     2     6    10    14    18    21   
     3     7    11    15    19    22
     4     8    12    16    20    23];
new_idx = randperm(size(A,2)/2)*2-[1; 0]
A = A(:,new_idx(:)) % A(:,[5 6 3 4 1 2])
4 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Deep Learning Toolbox in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

