Coordinates of graph nodes

4 次查看(过去 30 天)
Deepa Maheshvare
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.

回答(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