MATLAB Answers

0

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

Asked by Ashuftah Shigri on 20 Oct 2019
Latest activity Edited by 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.

Products


Release

R2017b

1 Answer

Answer by Bruno Luong
on 20 Oct 2019
Edited by Bruno Luong
on 20 Oct 2019
 Accepted Answer

A=mod((0:3)+(0:3)',4)+1;
R=A(randperm(end),randperm(end))

  0 Comments

Sign in to comment.