%% Subgraph with Node and Edge Properties
% Create and plot a weighted graph with named nodes.

s = [1 1 1 2 2 2 8 8 8 8];
t = [2 3 4 5 6 7 9 10 11 12];
weights = [10 30 40 80 60 60 20 30 90 80];
names = {'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L'};
G = graph(s,t,weights,names);
plot(G,'EdgeLabel',G.Edges.Weight)

%
% Extract a subgraph that contains node 'B' and all of its neighbors. subgraph preserves the node names and edge weights. However, the numeric node IDs in H are renumbered compared to G.

N = neighbors(G,'B');
H = subgraph(G, ['B'; N]);
plot(H,'EdgeLabel',H.Edges.Weight)

% Copyright 2015 The MathWorks, Inc.