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

조회 수: 1 (최근 30일)
Matlab2010
Matlab2010 2016년 3월 11일
편집: Matlab2010 2016년 3월 14일
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