www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/EdgeListDigraphConstructionWithNodeNamesAndEdgeWeightsExample.m

    %% Edge List Graph Construction with Node Names and Edge Weights
% Create and plot a cube graph using a list of the end nodes of each edge.
% Specify node names and edge weights as separate inputs.

% Copyright 2015 The MathWorks, Inc.

s = [1 1 1 2 2 3 3 4 5 5 6 7];
t = [2 4 8 3 7 4 6 5 6 8 7 8];
weights = [10 10 1 10 1 10 1 1 12 12 12 12];
names = {'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H'};
G = digraph(s,t,weights,names)

%%
%
plot(G,'Layout','force','EdgeLabel',G.Edges.Weight)