how to obtain adjacency matrix?

조회 수: 1 (최근 30일)
muhammad ismat
muhammad ismat 2018년 4월 7일
댓글: muhammad ismat 2018년 4월 7일
if i have data
1 2 3 4
2 3 5 6
3 5 6 7
in first row the element 1 has a connection with elements 2,3,4. And so on in remaining rows, so i want the adjacency matrix as
0 1 1 1 0 0 0
1 0 1 0 1 1 0
1 1 0 0 1 1 1
1 0 0 0 0 0 0
0 1 1 0 0 0 0
0 1 1 0 0 0 0
0 0 1 0 0 0 0

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 7일
Same basic technique as in https://www.mathworks.com/matlabcentral/answers/390250-how-to-calculate-adjacency-matrix#answer_311752 which is waiting for a response from you.
A = [1 2 3 4
2 3 5 6
3 5 6 7];
[r, c, s] = find(A(:,2:end));
adj = full(sparse([r,s],[s,r],1));
  댓글 수: 1
muhammad ismat
muhammad ismat 2018년 4월 7일
Thank you very much Walter Roberson for your advance

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by