MATLAB Answers

mr mo
0

How to randomly moving rows of a matrix

Asked by mr mo
on 2 Dec 2017
Latest activity Commented on by mr mo
on 2 Dec 2017
I have a hypothetical matrix named A, e.g.
A=[1 2 3
4 5 6
7 8 9
4 6 8
3 4 7
6 8 9
2 4 9
2 3 7
1 5 7
9 6 7];
I want to move the rows of A randomly to have a new matrix A with different arrange of rows.
How can I do that?
Thanks.

  0 Comments

Sign in to comment.

1 Answer

Answer by the cyclist
on 2 Dec 2017
 Accepted Answer

randomOrder = randperm(size(A,1));
newA = A(randomOrder,:);

  1 Comment

Thank you very much.

Sign in to comment.