Setting Edge Lengths equal to Weights in 2015B+ for graph.m

1 次查看(过去 30 天)
In 2015B graph.m is introduced graph.m.
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.

回答(1 个)

Steven Lord
Steven Lord 2016-3-14
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.

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by