Create a graph from removed edges

10 ビュー (過去 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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by