Digraph: for all nodes calculate all successors
2 views (last 30 days)
Show older comments
Hello everyone,
Considering digraph “G”, I would like to implement a code that for every node “i” in “G” it allows me to calculate a list of all successors of node “i”. How can I do this?
s = [1 1 1 2 2 3 3 4 4];
t = [2 3 4 5 6 7 8 9 10];
names = {'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'l'};
G = digraph (s,t,[],names);
S=successors(G,'a') %how to do this for all nodes?
0 Comments
Accepted Answer
Voss
on 20 Dec 2021
Here is one way:
all_S = cell(G.numnodes,1);
for i = 1:G.numnodes
all_S{i} = successors(G,G.Nodes{i,1});
end
More Answers (0)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!