Effacer les filtres
Effacer les filtres

matrix - change columns randomly

4 vues (au cours des 30 derniers jours)
Jonny
Jonny le 16 Oct 2011
Commenté : Ruchi Agarwal le 7 Jan 2020
Hi, how can I change randomly the positions of entire columns in a matrix [nxm]? For example, I want to change my matrix
A=[ 1 2 3 5 4 ;
2 2 2 2 2 ;
4 5 6 7 7 ;
8 9 8 8 8 ;
9 9 9 9 9 ]; to change into
B=[ 3 5 4 2 1;
2 2 2 2 2;
6 7 7 5 4;
8 8 8 9 8;
9 9 9 9 9];
Thank you :)

Réponses (1)

Wayne King
Wayne King le 16 Oct 2011
A random shuffling of the columns of A. One way:
cols = size(A,2);
P = randperm(cols);
B = A(:,P);
  1 commentaire
Ruchi Agarwal
Ruchi Agarwal le 7 Jan 2020
how to restore original columns after randperm?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices 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!

Translated by