Coordinates of graph nodes

35 views (last 30 days)
Deepa Maheshvare
Deepa Maheshvare on 26 Jan 2020
Commented: Deepa Maheshvare on 26 Jan 2020
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 Comments
Mohammad Sami
Mohammad Sami on 26 Jan 2020
Please see the answer from John on how to find the coordinates of new nodes equally spaced between two existing nodes

Sign in to comment.

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!