Create a graph from removed edges

조회 수: 9 (최근 30일)
Sim
Sim 2020년 4월 20일
편집: Sim 2020년 4월 20일
Hi, I have a graph G, from which I removed some edges, getting Grm.
Now I would need to get the graph composed only by the removed edges, but with the same nodes as in G, i.e. the graph G2 = G - Grm.
The following works:
% create a graph "G" and plot it
s = [1 1 1 2 3 4 4 5 5 6 7];
t = [2 4 8 3 4 5 8 6 8 7 8];
x = [0.5 1 1.5 1.5 1.5 1 0.5 0.5];
y = [0.5 0.5 0.5 1 1.5 1.5 1.5 1];
G = graph(s,t);
G.Nodes.X = x'; G.Nodes.Y = y';
plot(G,'XData',x,'YData',y)
% remove edges and plot the remaining graph "Grm"
rm_s = [1 4 4];
rm_t = [8 5 8];
Grm = rmedge(G,rm_s,rm_t);
figure
plot(Grm,'XData',x,'YData',y)
% plot the graph of removed edges "G2 = G - Grm"
G2 = graph(rm_s,rm_t)
figure
plot(G2,'XData',x,'YData',y)
Unfortunately, this does not work anymore when the edges rm_s and rm_t composing G2 are not composed by the last node in the s and t sets . For example, that does not work by removing the following edges (as you can see I don't remove any edge composed by the node 8, which is the last node in the s and t sets):
rm_s = [1 4];
rm_t = [4 5];
Is there any smart way to create G2 in the very likely case that the "removed edges", which is composed of, do not include the last node in the s and t sets?
Maybe directly from G, by removing all edges, excluding rm_s and rm_t?

채택된 답변

Christine Tobler
Christine Tobler 2020년 4월 20일
The graph constructor has a syntax that specifies the number of nodes of the graph:
graph(s, t, [], numnodes)
if you pass the number of nodes of G in that should address it.
  댓글 수: 1
Sim
Sim 2020년 4월 20일
Thanks a lot! It is working!
For the above mentioned example I used:
G2 = graph(rm_s,rm_t,[],8)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by