How can I keep the coordinates of a graph's nodes unchanged after removing a specific edge?

4 ビュー (過去 30 日間)
Hello,
I'm using the following built in function:
Tf=rmedge(G,edge); %Variable edge here is chosen randomly.
to remove an edge (link) from a graph. How can I keep the coordinates of G's nodes unchanged after removing that link?
Kindly see the attached two pictures to have a better visualization of what I'm looking for.(I'm removing the link between nodes 4 and 6).
Many thanks!

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 13 日
You can use the XData and YData property of the graphPlot object to fix their position. Check the following example
G = digraph(1,2:5);
G = addedge(G,2,6:15);
G = addedge(G,15,16:20);
subplot(2,2,1);
Gh = plot(G);
x = Gh.XData;
y = Gh.YData;
rand_edge = randi([1 10]);
G_new = rmedge(G, rand_edge);
subplot(2,2,2);
Gh_new1 = plot(G_new); % changed position of the removed node
subplot(2,2,3);
Gh_new2 = plot(G_new, 'XData', x, 'YData', y); % edge removed but nodes at same position
  2 件のコメント
Asaf McRock
Asaf McRock 2020 年 12 月 13 日
Thank you very much, sir!
This is so brilliant.
Ameer Hamza
Ameer Hamza 2020 年 12 月 13 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (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