%% Incoming Neighbor Distances in Directed Graph
% Create and plot a directed graph with weighted edges.

s = {'a' 'a' 'a' 'b' 'c' 'c' 'e' 'f' 'f'};
t = {'b' 'c' 'd' 'a' 'a' 'd' 'f' 'a' 'b'};
weights = [1 1 1 2 2 2 2 2 2];
G = digraph(s,t,weights);
plot(G,'EdgeLabel',G.Edges.Weight)

%
% Determine the nearest nodes within a radius of 1 from node 'a', measured by outgoing path distance from node 'a'.

nn_out = nearest(G,'a',1)

%
% Determine all of the nodes that have incoming paths leading to node 'a' by specifying the radius as Inf.

nn_in = nearest(G,'a',Inf,'Direction','incoming')

% Copyright 2012 The MathWorks, Inc.