%% Extract Subgraph
% Create and plot a graph.

s = [1 1 1 1 2 2 2 2 2 2 2 2 2 2 15 15 15 15 15];
t = [3 5 4 2 14 6 11 12 13 10 7 9 8 15 16 17 19 18 20];
G = graph(s,t);
plot(G,'Layout','force')

%
% Extract a subgraph from G by specifying which nodes to include. The node numbering in the subgraph is reset.

idx = [2 15 16 17 18 19 20 1 3 4 5];
H = subgraph(G,idx);
plot(H,'Layout','force')

% Copyright 2015 The MathWorks, Inc.