Effacer les filtres
Effacer les filtres

How to calculate adjacency matrix ?

10 vues (au cours des 30 derniers jours)
muhammad ismat
muhammad ismat le 23 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 commentaires
Guillaume
Guillaume le 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 le 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

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 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));

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by