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

6 ビュー (過去 30 日間)
Ashuftah Shigri
Ashuftah Shigri 2019 年 10 月 20 日
コメント済み: Bruno Luong 2022 年 12 月 4 日
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.

採用された回答

Bruno Luong
Bruno Luong 2019 年 10 月 20 日
編集済み: Bruno Luong 2019 年 10 月 20 日
A=mod((0:3)+(0:3)',4)+1;
R=A(randperm(end),randperm(end))
R = 4×4
1 3 4 2 2 4 1 3 3 1 2 4 4 2 3 1
  2 件のコメント
Pool
Pool 2022 年 12 月 4 日
Is it possible to make this into a 16x4 matrix? with fixed, non-random values?
A=mod((0:3)+(0:15)',2)+1;
r=A(randperm(end),randperm(end))
s=zeros(16,4);
% t=zeros(16,4);
r(r==2)=5;
This does not make unqieu arrays though
Bruno Luong
Bruno Luong 2022 年 12 月 4 日
@Pool It's not possible : You can never have unique values on 16 rows and 4 colums with only 2 values.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by