Borrar filtros
Borrar filtros

Adding nodes from a sub-graph to a larger graph

1 visualización (últimos 30 días)
L'O.G.
L'O.G. el 20 de Abr. de 2022
Editada: Bruno Luong el 21 de Abr. de 2022
I have an adjacency matrix for a graph consisting of 10 nodes and the edges between them. But they are part of a larger graph, and I want to construct the adjacency matrix for that larger graph.
I know what node IDs the nodes 1-10 should correspond to in the larger graph, but I don't know how to set them. Is there an easy way to do this? The function addnode looks helpful, but I think it would keep the original node IDs the same and just add to that, whereas the node IDs of the original set will change when they become part of the larger graph.
Another option might be to do this with a purely array-based approach rather than using graphs. As a simple example, say I have the following adjacency matrix
A =
0 0 1
0 0 1
1 1 0
which corresponds to three nodes and the edges between them. Say these three nodes are actually nodes 1, 5, and 6 of a larger graph with 6 nodes. How would I re-arrange that adjacency matrix in the simplest case where the other nodes form no edges (so would correspond to 0's in the adjacency matrix)?

Respuesta aceptada

Bruno Luong
Bruno Luong el 21 de Abr. de 2022
Editada: Bruno Luong el 21 de Abr. de 2022
Build Abig as adjacent matrix of empty graph with 6 nodes, then insert A to Abig
A = [0 0 1;
0 0 1;
1 1 0 ];
newpos = [1 5 6];
Abig = sparse(6,6);
Abig(newpos,newpos) = Abig(newpos,newpos) | A;
Gbig = graph(Abig);
plot(Gbig);

Más respuestas (0)

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by