# Adding nodes from a sub-graph to a larger graph

조회 수: 1 (최근 30일)
L'O.G. 2022년 4월 20일
편집: Bruno Luong 2022년 4월 21일
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 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);

댓글을 달려면 로그인하십시오.

### 카테고리

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