Create a graph from removed edges
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Christine Tobler
on 20 Apr 2020
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.
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!