how to plot shortest path from cost matrix

1 view (last 30 days)
tumpa pal
tumpa pal on 16 May 2020
Commented: Ameer Hamza on 17 May 2020
0 4.4653 76.113 63.1 45.582 11.717 84.008 18.886 39.609 46.586
4.4653 0 80.473 67.12 47.357 12.567 86.033 14.621 44.039 48.904
76.113 80.473 0 21.173 63.425 74.317 70.006 93.226 36.837 56.915
63.1 67.12 21.173 0 42.621 58.707 51.508 78.212 28.709 36.057
45.582 47.357 63.425 42.621 0 34.848 38.767 51.072 43.846 6.5779
11.717 12.567 74.317 58.707 34.848 0 73.579 19.54 39.703 36.726
84.008 86.033 70.006 51.508 38.767 73.579 0 89.416 70.533 37.599
18.886 14.621 93.226 78.212 51.072 19.54 89.416 0 57.495 54.308
39.609 44.039 36.837 28.709 43.846 39.703 70.533 57.495 0 39.22
46.586 48.904 56.915 36.057 6.5779 36.726 37.599 54.308 39.22 0
from this how can I draw the shortest path

Answers (1)

Ameer Hamza
Ameer Hamza on 16 May 2020
First create a graph from this matrix and then use shortestpath().
M = ...
[0 4.4653 76.113 63.1 45.582 11.717 84.008 18.886 39.609 46.586
4.4653 0 80.473 67.12 47.357 12.567 86.033 14.621 44.039 48.904
76.113 80.473 0 21.173 63.425 74.317 70.006 93.226 36.837 56.915
63.1 67.12 21.173 0 42.621 58.707 51.508 78.212 28.709 36.057
45.582 47.357 63.425 42.621 0 34.848 38.767 51.072 43.846 6.5779
11.717 12.567 74.317 58.707 34.848 0 73.579 19.54 39.703 36.726
84.008 86.033 70.006 51.508 38.767 73.579 0 89.416 70.533 37.599
18.886 14.621 93.226 78.212 51.072 19.54 89.416 0 57.495 54.308
39.609 44.039 36.837 28.709 43.846 39.703 70.533 57.495 0 39.22
46.586 48.904 56.915 36.057 6.5779 36.726 37.599 54.308 39.22 0];
G = graph(M);
path = shortestpath(G, 1, 10) % source is node 1 and destination is node 10
  2 Comments
tumpa pal
tumpa pal on 17 May 2020
my MATLAB version is 2015a..
G = graph(M); this function is not supporting.
Please help me how could I solve this
Ameer Hamza
Ameer Hamza on 17 May 2020
It was introduced in R2015b. Before that, it appears that some functions related to graphs were present in the bioinformatics toolbox, but not in basic MATLAB. Maybe you can try the following packages and see if they can work for your problem.

Sign in to comment.

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!