randperm
    13 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
How can I use randperm for a nx2 matrix?
1 commentaire
  Dr. Seis
      
 le 11 Nov 2011
				"randperm" only takes 1 scalar input argument. Can you give a sample of an input nx2 matrix AND what you would expect the output to be?
Réponses (3)
  Jonathan
      
 le 11 Nov 2011
        If you want to randomly permute the rows, do something like the following.
n = 5;
A = reshape(1:2*n, n, 2)
B = A(randperm(n), :)
If you want to randomly permute all elements, do something like this instead.
C = reshape(A(randperm(2*n)), n, 2)
1 commentaire
  Jonathan
      
 le 11 Nov 2011
				@Miriam, to permute the columns separately do this.
 D = A;
 D(:,1) = D(randperm(n),1);
 D(:,2) = D(randperm(n),2);
Voir également
Catégories
				En savoir plus sur Logical dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



