Coordinates of graph nodes

34 ビュー (過去 30 日間)
Deepa Maheshvare
Deepa Maheshvare 2020 年 1 月 26 日
コメント済み: Deepa Maheshvare 2020 年 1 月 26 日
I've the following code
t = [1 1 1 1 2 2 3 4 4 5 6];
h = [2 3 4 5 3 6 6 5 7 7 7];
pos = [75 25; 115 45; 90 60; 10 5; 45 0; 45 55; 0 25]; % coordinates of nodes 1:7
g = graph(t,h);
plot(g, 'XData', pos(:,1), 'YData', pos(:,2));
where the coordinates of the initial set of nodes are specified to create the graph layout.
I want to add new nodes positioned between existing nodes. I don't have the coordinates of these new nodes.
For instance, I have deleted the existing edge between node 1 and 8 and added a new node and 2 new edges.
g = rmedge(g,1,2);
g = addedge(g,1,8);
g = addedge(g,8,2);
plot(g)
However, I am not sure how to specify the position of the new node. I want it to be positioned on the edge [1 2] , probably midway (Note: the exact position will vary depending on the number of nodes added in between node 1 and node 2. If two nodes are added, both has to be positioned along the straight line connecting edge [1 ---- 2])
Can some kind of a linear interpolation function be used to find the position of new node given the coordinates of end nodes (i.e given the coordinates of node 1 and 2 , I want the position of node 8 in betwen 1 and 2)? I'd like to keep this general. If n nodes have to be added , all n nodes should be placed equidistant.
Any suggestions on how to do this will be really helpful.
  2 件のコメント
Mohammad Sami
Mohammad Sami 2020 年 1 月 26 日
Please see the answer from John on how to find the coordinates of new nodes equally spaced between two existing nodes
Deepa Maheshvare
Deepa Maheshvare 2020 年 1 月 26 日
Thanks!

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

回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by