%% Label Graph Nodes
% Create and plot a graph.

s = [1 1 2 2 3 4 5 5];
t = [2 3 3 4 4 5 1 2];
G = digraph(s,t);
h = plot(G);

%
% The plot function automatically labels the graph nodes with their node indices (or with their node names, if available). Use text labels for some of the graph nodes instead.

labelnode(h,[1 2],{'source' 'target'})

%
% Label node 3 and node 4 as 'A'. Since the node labels do not change the underlying graph, G, the labels can contain duplicate names (the official node names in G must always be unique).

labelnode(h,[3 4],'A')

% Copyright 2015 The MathWorks, Inc.