how to randomize the column position of a matrix?

Asked by Daud on 9 Sep 2012
Latest activity Commented on by Dishant Arora on 9 Sep 2012

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.

0 Comments

Daud

Products

1 Answer

Answer by Dishant Arora on 9 Sep 2012
Accepted answer
ind=randperm(size(A,2));
C=zeros(size(A));
C=A(:,ind);

ind preserves the order of randomization.

2 Comments

Jan Simon on 9 Sep 2012

The pre-allocation by zeros is useless here. A pre-allocation is useful only, if the array would grow iteratively.

Dishant Arora on 9 Sep 2012

Thanks jan, I must take care of it in future.

Dishant Arora

Contact us