Convert Array to Adjacency matrix
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Guillaume
el 11 de Mzo. de 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 comentarios
Ver también
Categorías
Más información sobre Graph and Network Algorithms en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!