www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/TransitiveClosureOfGraphExample.m

    %% Transitive Closure of Graph
% Create and plot a directed graph.

% Copyright 2015 The MathWorks, Inc.

G = digraph([1 2 3 4 4 4 5 5 5 6 7 8],[2 3 5 1 3 6 6 7 8 9 9 9]);
plot(G)

%%
% Find the transitive closure of graph |G| and plot the resulting graph.
% |H| contains the same nodes as |G|, but has additional edges.
H = transclosure(G);
plot(H)

%%
% The transitive closure information in |H| can be used to answer
% reachability questions about the original graph, |G|. 
%
% Determine the nodes in |G| that can be reached from node 1. These nodes
% are the successors of node 1 in the transitive closure graph, |H|.
N = successors(H,1)