Why aren't weight values incorporated into graph and digraph?

조회 수: 4 (최근 30일)
Nathan Garcia
Nathan Garcia 2022년 2월 23일
댓글: Nathan Garcia 2022년 2월 23일
Hi,
I would like to create a network graph using the graph function or the digraph function. I would like edges lengths in the network to reflect values that I have in a vector. I tried the examples provided in the video at the following page.
(https://www.mathworks.com/support/search.html/videos/graph-and-digraph-classes-106802.html?fq[]=asset_type_name:video&fq[]=category:matlab/graph-and-network-algorithms&page=1)
It describes how to add weight data to the graph and digraph functons. The video gives the impression that the distance of the edges can be changed by changing the "weight" value. However, the distances do not reflect the weight values in the video example. Also when I change the values dramatically there is no change in the distance of edges. Is there a fix to this or another graphing function that I can use?

채택된 답변

Steven Lord
Steven Lord 2022년 2월 23일
You can have the edge weights influence the layout of the graph or digraph but it is possible to specify edge weights such that drawing the network with edges of exactly those lengths is impossible. One such example that violates the triangle inequality is:
EndNodes = [1 2; 1 3; 2 3];
Weights = [5; 5; 20]; %
E = table(EndNodes, Weights);
g = graph(E);
plot(g)
See the example "Graph Layout Based on Edge Weights" on the documentation page for the layout function for an example. In the case of this simple a graph the layout using 'force' with or without a WeightEffect looks the same, but for a more complicated graph (like a randomly weighted buckyball) it may not.
B = graph(bucky);
B.Edges.Weight = randi(20, numedges(B), 1);
figure
plot(B); % No weight effect
figure
h = plot(B);
layout(h, 'force', 'WeightEffect', 'direct') % Higher weighted edges tend to be longer
figure
plot(B, 'layout', 'force', 'WeightEffect', 'inverse') % higher weight, shorter edge

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by