Generating a random symmetric matrix
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MK96
am 16 Nov. 2016
Bearbeitet: Alexandra Harkai
am 16 Nov. 2016
I am trying to generate a random symmetric matrix consisting of 1s and 0s (adjacency matrix)
I have the following;
A = randi(2,N,N) - 1 % Generates a random nxn matrix with values 0 or 1 (Adjacency Matrix)
However this produces a random adjacency matrix which is not symmetric.
How can I change this code to make the matrix symmetric?
0 Kommentare
Akzeptierte Antwort
Alexandra Harkai
am 16 Nov. 2016
Bearbeitet: Alexandra Harkai
am 16 Nov. 2016
A = randi(2,N,N) - 1;
A = A - tril(A,-1) + triu(A,1)';
This will copy the upper triangle to the lower triangle.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!