Setting Edge Lengths equal to Weights in 2015B+ for graph.m
2 views (last 30 days)
Show older comments
s = [1 1 1 2 2 3 3 4 5 5 6 7];
t = [2 4 8 3 7 4 6 5 6 8 7 8];
weights = [10 10 1 10 1 10 1 1 12 12 12 12];
names = {'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H'};
G = graph(s,t,weights,names)
plot(G);
h=get(gca, 'Children');
When matlab plots the graph, all the edges are approximately the same length (they are approx as matlab does the plotting to ensure labels are not obstructed).
Question 1 How do I set the edge lengths to be equal to the weights?
Question 2 How can I plot in 3D using a Cartesian coordinate system? I assume there are some assumptions I would need to make in order to allow this.
0 Comments
Answers (1)
Steven Lord
on 14 Mar 2016
I don't think any of the existing layout methods will determine the coordinates automatically, and in some cases that would be an impossible task. Consider a graph with three vertices, where the weights on edges (1, 2) and (1, 3) are both 1 but the weight on edge (2, 3) is 3. By the triangle inequality you can't draw this triangle with straight edges.
If you can compute the coordinates yourself you can set the XData and YData properties of the plot object. If you want to have a layout method that can compute those coordinates automatically, contact Technical Support and submit that as an enhancement request.
0 Comments
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!