Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Steven Lord
Steven Lord il 23 Feb 2022
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

Più risposte (0)

Categorie

Scopri di più su Networks in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by