Adding nodes from a sub-graph to a larger graph

1 次查看(过去 30 天)
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)?

采纳的回答

Bruno Luong
Bruno Luong 2022-4-21
编辑:Bruno Luong 2022-4-21
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by