how to randomize the column position of a matrix?

3 visualizzazioni (ultimi 30 giorni)
suppose A=[D G H K ... O];
i want to do C=[H D O .... G.. K]
i also want to keep the information about the order of randomization to use it other matrix further manipulation.

Risposta accettata

Dishant Arora
Dishant Arora il 9 Set 2012
ind=randperm(size(A,2));
C=zeros(size(A));
C=A(:,ind);
ind preserves the order of randomization.
  2 Commenti
Jan
Jan il 9 Set 2012
Modificato: Jan il 9 Set 2012
The pre-allocation by zeros is useless here. A pre-allocation is useful only, if the array would grow iteratively.
Dishant Arora
Dishant Arora il 9 Set 2012
Thanks jan, I must take care of it in future.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by