Coordinates of graph nodes

조회 수: 3 (최근 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 CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by