%% Graph Layout Based on Edge Weights
% Plot a graph using the 'WeightEffect' name-value pair to make the length of graph edges proportional to their weights.
%
% Create and plot a directed graph with weighted edges.

s = [1 1 1 1 1 2 2 2 3 3 3 3 3];
t = [2 4 5 6 7 3 8 9 10 11 12 13 14];
weights = randi([1 20],1,13);
G = graph(s,t,weights);
p = plot(G,'Layout','force','EdgeLabel',G.Edges.Weight);

%
% Recompute the layout of the graph using the 'WeightEffect' name-value pair, so that the length of each edge is proportional to its weight. This makes it so that the edges with the largest weights are the longest.

layout(p,'force','WeightEffect','direct')

% Copyright 2012 The MathWorks, Inc.