%% Ignore Edge Weights
% Create and plot a directed graph with weighted edges.

s = [1 1 1 2 5 3 6 4 7 8 8 8];
t = [2 3 4 5 3 6 4 7 2 6 7 5];
weights = [100 10 10 10 10 20 10 30 50 10 70 10];
G = digraph(s,t,weights);
plot(G,'EdgeLabel',G.Edges.Weight)

%
% Find the shortest path distance between all pairs of graph nodes.

d = distances(G)

% Since G is a directed graph, d is not symmetric, and d(i,j) corresponds to the distance between nodes i and j. The Inf values in d correspond to nodes that are unreachable. For example, since node 1 has no predecessors, it is not possible to reach node 1 from any other node in the graph. So the first column of d contains many Inf values to reflect that node 1 is unreachable.
%
% By default, distances uses the edge weights to compute the distances. Specify 'Method' as 'unweighted' to ignore the edge weights and treat all edge distances as 1.

d1 = distances(G,'Method','unweighted')

% Copyright 2015 The MathWorks, Inc.