Filter löschen
Filter löschen

Adding nodes from a sub-graph to a larger graph

1 Ansicht (letzte 30 Tage)
L'O.G.
L'O.G. am 20 Apr. 2022
Bearbeitet: Bruno Luong am 21 Apr. 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)?

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 21 Apr. 2022
Bearbeitet: Bruno Luong am 21 Apr. 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);

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by