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

1 Ansicht (letzte 30 Tage)
Matlab2010
Matlab2010 am 11 Mär. 2016
Bearbeitet: Matlab2010 am 14 Mär. 2016
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.

Antworten (1)

Steven Lord
Steven Lord am 14 Mär. 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.

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by