%% Shortest Path Distances to Specified Targets
% Create and plot a graph.

s = [1 1 1 2 2 3 3 4 5 5 6 7 8  8 10 11];
t = [2 3 10 4 12 5 4 6 6 7 9 8 9 11 11 12];
G = graph(s,t);
plot(G)

%
% Find the shortest path distances from nodes 5 and 7 to nodes 2 and 3.

sources = [5 7];
targets = [2 3];
d = distances(G,sources,targets)

%
% Use d to find the shortest path distance between node 7 and node 3. In this case, d(i,j) is the distance from node sources(i) to node targets(j).

d(2,2)

% Copyright 2015 The MathWorks, Inc.