MATLAB Answers

Generate a random matrix without repeating any value in row and column.

3 views (last 30 days)
Ashuftah Shigri
Ashuftah Shigri on 20 Oct 2019
Edited: Bruno Luong on 20 Oct 2019
How can I generate a random matrix without repeating any value in row and column. form "randi" function.
If we generate a matrix.
then the answer may be like this
randi(4,4)
ans =
4 2 3 1
3 4 1 2
1 3 2 4
2 1 4 3
this is just for example not generated matrix.
I have used the "unique" function. by this i can control the repeatition in row only.

  0 Comments

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 20 Oct 2019
Edited: Bruno Luong on 20 Oct 2019
A=mod((0:3)+(0:3)',4)+1;
R=A(randperm(end),randperm(end))

  0 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Translated by