How to calculate adjacency matrix ?

20 visualizzazioni (ultimi 30 giorni)
muhammad ismat
muhammad ismat il 23 Mar 2018
Risposto: Walter Roberson il 24 Mar 2018
if i have data rearranged as follow
0 1 2 3
1 3 5 7
2 4 6 7
where this data mean that first element of first row connect with remaining element in first row and second element of second row connect with remaining element in second row so i want to calculate the adjacency matrix in the form
0 1 1 1 0 0 0 0
0 0 0 1 0 1 0 1
0 0 0 0 4 0 1 1
  2 Commenti
Guillaume
Guillaume il 23 Mar 2018
I do not understand first element of first row connect with remaining element in first row
An adjacency matrix is always square. So your output is not an adjacency matrix.
You need to give a much better explanation of what your input matrix represents and how to generate your not_an_adjacency_matrix output from it.
muhammad ismat
muhammad ismat il 24 Mar 2018
first row mean that user number 0 connect with user number 1, 2, 3 and there is a relation between user 1 and users 3, 5, 7 and so on. i want to obtain on adjacency matrix
0 1 1 1 0 0 0 0
1 0 0 1 0 1 0 1
1 0 0 0 1 0 1 1
1 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 1 1 0 0 0 0 0

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 24 Mar 2018
A = [0 1 2 3
1 3 5 7
2 4 6 7];
[r, c, s] = find(A);
adj = full(sparse(r,s+1,1));

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by