Reputation:
I have an array with two columns and each row is a unique pair. When I shuffle, I want the array to be shuffled among pairs, not as two separate columns.
This is the array
A=[2 1;
2 1;
2 2;
2 2;
2 3;
2 3;
2 4;
2 4;
1 5;
1 6;
1 7;
1 8;
1 9;
1 9;
1 9;
1 9]
So after the shuffling, I want the pairs to be preserved, only their ordering can change.
Upvotes: 0
Views: 666
Reputation: 4388
So size(A) = [16, 2]
and you want to shuffle the rows without disturbing the pairs. Try:
A = A(randperm(16), :);
randperm(16)
gives the numbers 1..16 in a random order, and these are used to index the rows of A.
Upvotes: 4