Random symmetric binary matrix

I want to make a symmetric (100x100) matrix with binary values and the numbers on the diagonal have to be 0. Can anyone help me?

回答 (1 件)

Star Strider
Star Strider 2016 年 11 月 28 日

0 投票

See if this does what you want:
N = 6; % Matrix Size
M = randi([0 1], N);
Mu = triu(M);
Ml = Mu';
Mout = Mu + Ml;
Mout = Mout - diag(diag(Mout))
I kept the matrix size small here so you can verify that it does what you want. Change it to 100 for your matrix.

カテゴリ

ヘルプ センター および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

質問済み:

2016 年 11 月 28 日

回答済み:

2016 年 11 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by