Convert Array to Adjacency matrix
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
M = [
0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0
0 0 0 1 1 0 0 1 0 1 1 0 0 1 1 0 1 1
0 0 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 0
1 0 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 0 0 1 0 0 0 0 1 1 0 0 0 1
0 0 1 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 1
0 1 1 1 1 0 1 1 0 1 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
0 0 1 1 1 0 0 1 0 1 1 0 0 1 0 0 0 0
0 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 0 0
]
I have the following array M which I need to convert to adjacency matrix. Can someone guide me as to how this needs to be done ?
0 commentaires
Réponses (1)
Guillaume
le 11 Mar 2016
If your matrix represents which vertices are connected to which with 1, then it is already an adjacency matrix. If not, then you'll have to give more details about what you want.
Note that since 2015b, matlab has some functions that make it easier to manipulate graphs with the graph and digraph classes.
g = digraph(M); %since your matrix is not symmetrical it must be a directed graph
g.adjacency
Note that the output of the above is simply the sparse representation of M, so you can achieve the same output with any version of matlab with:
sparse(M)
0 commentaires
Voir également
Catégories
En savoir plus sur Directed Graphs dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!