필터 지우기
필터 지우기

Directed matrix to Undirected matrix

조회 수: 1 (최근 30일)
Vishnu Kant
Vishnu Kant 2018년 10월 31일
답변: Akira Agata 2018년 10월 31일
I have directed network matrix which i want to convert to undirected matrix. Suppose i have following directed matrix
G =[0 1 0 1; 0 0 1 1; 1 1 0 1; 0 0 0 0];
which i want to convert to following undirected matrix
Y = [0 1 1 1; 1 0 1 1; 1 1 0 1; 1 1 1 0];
I run the following code
for i = 1 : m
for j = 1 : n
if G(i,j) == 1
G(j,i) = G(i,j);
else
G(i,j)= 0 ;
end
end
end
This code run successfully but instead of overwriting matrix G I want a function which create a new undirected matrix Y from the directed matrix G

채택된 답변

Akira Agata
Akira Agata 2018년 10월 31일
How about the following?
Y = G + G' > 0;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Undirected Graphs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by