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

3 ビュー (過去 30 日間)
Aswin Sandirakumaran
Aswin Sandirakumaran 2018 年 7 月 1 日
コメント済み: navanit dubey 2020 年 11 月 17 日
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 件のコメント
Paolo
Paolo 2018 年 7 月 1 日
Can you share the code with which the image was generated?
Aswin Sandirakumaran
Aswin Sandirakumaran 2018 年 7 月 1 日
I just used addnode and addedge.

サインインしてコメントする。

回答 (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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by