Positioning new nodes in a graph

12 ビュー (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2020 年 1 月 30 日
回答済み: Ganesh Regoti 2020 年 2 月 4 日
I've the following graph
s = [1 1 1 2 2];
t = [2 3 4 2 5];
G = graph(s,t);
% plot
h = plot(G);
h.XData
h.YData
New nodes are added below
% add new nodes
G = addedge(G,[3 5],[6 7])
However, I want to position the new edges vertically (90 degree) above the existing nodes and not at the default positions.
For instance, the position of node 3 and 5 are [0.5492 0.9698] and [-0.8913 -0.9239] respectively.
I wish to retain the same x-coordinates for the new nodes 6 and 7 and add an offset to y-coordinate. e.g. offset = 0.05
The coordinates of 6 and 7 will be [0.5492 0.9698+offset] and [-0.8913 -0.9239+offset] .
Any suggestions on how this(or alternate ways) can be implemented will be really helpful.

採用された回答

Ganesh Regoti
Ganesh Regoti 2020 年 2 月 4 日
Hi,
As per my understanding, you want to customize node positions on plot. Here is the link you can refer to
Here is sample code
s = [1 1 1 2 2];
t = [2 3 4 2 5];
G = graph(s,t);
% plot
h = plot(G);
h.XData
h.YData
x = h.XData;
y = h.YData;
G = addedge(G,[3 5],[6 7])
x = [x , x(3), x(5)];
y = [y, y(3)+0.5, y(5)+0.5]
plot(G,'XData',x,'YData',y);
Hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by