Alex Kps Bdc
Alex Kps Bdc

Reputation: 23

Edges' length in diagraph on Matlab

I need to create a digraph on Matlab. I have the sources, the targets and the matrix with the weights. Normally, all that is needed is the line:

G = digraph(S,T,weights);

My problem is that although I don't have the coordinates of nodes, I do have the lengths of the edges linking the nodes. In order to have the weights being represented as edges' width, I have this:

LWidths = (1/max(G.Edges.Weight))*G.Edges.Weight;
p.LineWidth = LWidths;

How can I take into account also the length and have it imported from the user, and not by default?

Upvotes: 0

Views: 312

Answers (1)

Alex Kps Bdc
Alex Kps Bdc

Reputation: 23

After defining sources, targets, weights and lengths:

G = digraph(S,T,lengths);
p = plot(G);
G.Edges.Weight = lengths';
layout(p,'force','WeightEffect','direct')
G.Edges.LWidths = 7*weights'/max(weights);
p.LineWidth = G.Edges.LWidths;

network

, the edges lengths are dependent on the actual length thereof, and their width is proportional to their weights

Upvotes: 1

Related Questions