How to create a symmetric random matrix with zero diagonal and with entries just 0 and 1
12 ビュー (過去 30 日間)
古いコメントを表示
Mojtaba Mohareri
2021 年 6 月 5 日
コメント済み: Mojtaba Mohareri
2021 年 6 月 5 日
There is the follwoing code
d = 1000000*rand(N,1); % The diagonal values
t = triu(bsxfun(@min,d,d.').*rand(N),1); % The upper trianglar random values
M = diag(d)+t+t.'; % Put them together in a symmetric matrix
responding to the question "How to create a symmetric random matrix?" at MathWorks. But my question is a bit different. I was wondering if someone could help about creating a random symmetric random matrix with zero diagonal and with entries just 0 and 1.
Thanks in advance.
0 件のコメント
採用された回答
Walter Roberson
2021 年 6 月 5 日
編集済み: Walter Roberson
2021 年 6 月 5 日
N = 10;
temp = randi([0 1], N, N);
d = tril(temp,-1);
M1 = d + d.'
M2 = xor(temp, temp.')
5 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!