How to create a symmetric random matrix with zero diagonal and with entries just 0 and 1
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mojtaba Mohareri
il 5 Giu 2021
Commentato: Mojtaba Mohareri
il 5 Giu 2021
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 Commenti
Risposta accettata
Walter Roberson
il 5 Giu 2021
Modificato: Walter Roberson
il 5 Giu 2021
N = 10;
temp = randi([0 1], N, N);
d = tril(temp,-1);
M1 = d + d.'
M2 = xor(temp, temp.')
5 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!