%% Change Weights of Multigraph Edges
% Use findedge to change the weights of several multigraph edges.
%
% Create and plot a multigraph. This graph has two edges between node 2 and node 4.

s = [1 1 2 3 2 2];
t = [2 3 3 4 4 4];
weights = [10 20 30 40 10 10];
G = graph(s,t,weights);
plot(G,'EdgeLabel',G.Edges.Weight)

%
% Change the weights of the edges between nodes (3,2) and (2,4). Specify two outputs to findedge to get the end-node indices, m. This output is useful when there are multiple edges between two nodes, since idxOut can have more elements than the number of node pairs in s and t. The edge idxOut(1) = 3 connects the node pair (s(1),t(1)) = (3,2), and the edges idxOut(2) = 4 and idxOut(3) = 5 connect the edge (s(2),t(2)) = (2,4).

s = [3 2];
t = [2 4];
w = [1 4];
[idxOut, m] = findedge(G, s, t)

%

G.Edges.Weight(idxOut) = w(m);
plot(G,'EdgeLabel',G.Edges.Weight)

% Copyright 2012 The MathWorks, Inc.