Path between 2 nodes in a graph
Show older comments
How to check if a path exists between two nodes in a graph?
Accepted Answer
More Answers (1)
Christine Tobler
on 28 Sep 2020
Compute a path between the nodes, then check if the result is empty (this is returned by shortestpath if no path exists):
path = shortestpath(G, firstNode, secondNode)
pathExists = ~isempty(path);
2 Comments
Hari
on 4 Oct 2020
Bruno Luong
on 4 Oct 2020
Read Michael's answer that suggests using concomp
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!