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?

 채택된 답변

Alexandra Harkai
Alexandra Harkai 2016년 11월 16일
편집: Alexandra Harkai 2016년 11월 16일

4 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2016년 11월 16일

편집:

2016년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by