Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Aswin Sandirakumaran
Aswin Sandirakumaran el 1 de Jul. de 2018
Comentada: navanit dubey el 17 de Nov. de 2020
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 comentarios
Paolo
Paolo el 1 de Jul. de 2018
Can you share the code with which the image was generated?
Aswin Sandirakumaran
Aswin Sandirakumaran el 1 de Jul. de 2018
I just used addnode and addedge.

Iniciar sesión para comentar.

Respuestas (2)

Anton Semechko
Anton Semechko el 1 de Jul. de 2018
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 el 2 de Jul. de 2018
Call https://www.mathworks.com/help/matlab/ref/graph.shortestpath.html shortestpath() on the graph object to get the distances.

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by