Convert Array to Adjacency matrix
23 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Guillaume
il 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 Commenti
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!