how to obtain adjacency matrix?

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 7 Apr 2018
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 Commento
muhammad ismat
muhammad ismat il 7 Apr 2018
Thank you very much Walter Roberson for your advance

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by