%% Shortest Paths to Specified Target Node
% Find the shortest paths from each node in a graph to a target node, and plot the results.
% Create and plot a graph.

s = [1 1 1 1 1 1 1 2 2 7 7 7 7 9 9 3 3 1 6 4 8 10 6 8 4 5];
t = [2 3 4 5 6 8 7 6 7 5 6 8 9 6 8 6 10 10 10 10 10 11 11 11 8 8];
G = graph(s,t);
x = [0 0.5 -0.5 -0.5 0.5 0 1.5 0 2 -1.5 -2];
y = [0 0.5 0.5 -0.5 -0.5 2 0 -2 0 0 0];
plot(G,'XData',x,'YData',y)

%
% Find the shortest paths from each node in the graph to node 10. Plot the resulting tree.

TR = shortestpathtree(G,'all',10);
plot(TR)

% Copyright 2015 The MathWorks, Inc.