How to find distance between two nodes? including the nodes.

1 次查看(过去 30 天)
For example: In this graph i would like to find distance *between s1 and s3.
SO MY OUTPUT SHOULD LOOK LIKE : Distance = 7 (includes both edges and nodes)

回答(2 个)

Anton Semechko
Anton Semechko 2018-7-1
Download graph processing toolbox from FEX. Use Dijkstra's algorithm to get shortest path between pairs of nodes. Path length = distance between nodes = sum of edge weights along the path.

Walter Roberson
Walter Roberson 2018-7-2
Call https://www.mathworks.com/help/matlab/ref/graph.shortestpath.html shortestpath() on the graph object to get the distances.

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by