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

    %% Label Graph Nodes and Edges
% Create a directed graph, and then plot the graph with custom labels for
% the nodes and edges.

% Copyright 2015 The MathWorks, Inc.

s = [1 1 1 2 2 3 3 4 4 5 6 7];
t = [2 3 4 5 6 5 7 6 7 8 8 8];
G = digraph(s,t)

%%
%
eLabels = {'x' 'y' 'z' 'y' 'z' 'x' 'z' 'x' 'y' 'z' 'y' 'x'};
nLabels = {'{0}','{x}','{y}','{z}','{x,y}','{x,z}','{y,z}','{x,y,z}'};
plot(G,'Layout','force','EdgeLabel',eLabels,'NodeLabel',nLabels)