Reputation: 19
i need to make a random matrix, lets say size 3X4, where the values will be between 1-6, and each value will be reapeted exactly twice (in a random location in the matrix). how can i do that? thanks
Upvotes: 0
Views: 213
Reputation: 9864
You can create an array that contains the numbers 1 to 6 with required repition, say
A=[1:6, 1:6];
Then shuffle that array using randperm
and reshape it to a 3 by 4 matrix
>> B=reshape(A(randperm(12)), 3, 4)
B =
5 4 6 1
2 3 5 4
6 2 1 3
Upvotes: 9