File Exchange

image thumbnail

Dijkstra Shortest Path Routing

version 1.0 (3.17 KB) by

This function and example show shortest path routing based on Dijkstra algorithm.

36 Ratings



No License

This function performs Dijkstra algorithm based on the cost matrix, and shortest path can be found.

Comments and Ratings (52)

nana bu

报错Error: Missing MATLAB operator.是怎么回事

PLEASE the file

channa Silva

it is helpful

Really i can't run it. it shows following error

index out of bounds because numel(W)=1.
Error in dijkstra (line 52)

so next what can i do please suggest me ,its urgent.send me at my

Zhang Huiyuan

So bad, no description on each variable!! Cant get how to use it!!!

Hi, I am trying to work on a project to find the best shotest path alogrithm in performance between DIJKSTRA AND BELLFORD algorithms. I even have code but don't know how to run it. Can someone please help me.



Cosy (view profile)

Upps, commented the wrong file
Sorry for that...


Cosy (view profile)

Hi there,

what is wrong with this example:

G = [ 0 1 2;
1 0 0;
2 0 0 ]


result: [3 2 2]

Can you help me?


Yousof (view profile)

How can I use it?



alex (view profile)

can you send me at my email ( how the code works ?? urgently please!!


I'm having trouble using this for large datasets - it works fine for 10 start/end points, but take that up an to 1000 startpoints and endpoints, and my computer almost always runs out of memory. Any way to make it more efficient would be much appreciated.


Barsam (view profile)

Really helped me, thanks!

Jesus Luevano

anyone can help to solve a problem with this algorithm!


MAOFAN (view profile)

Well done


Meg (view profile)

can you please define the input such as farthestPreviousHop, farthestNextHop, and netcostmatrix?


Hakk1 (view profile)



well done


LA (view profile)





Seifi (view profile)

I met this Error in running the code:

??? Index exceeds matrix dimensions.
Error in ==> dijkstra at 77
if ( ( netCostMatrix(u, v) + distance(u)) < distance(v) )

Could you please tell me how do you define the input?


Rick (view profile)

Matthew Bays

Worked great the first time!

Ying liu

Alexander Wallar

im new to MATLAB and i was just wondering if you could give an example?


Maxime (view profile)

avdo tukic

Rolf Bartstra

Poor (or no!) description of input/output parameters. For large nr of nodes, n, the netCostMatrix (nxn) may require vast amounts of memory; a link-based description may be more appropriate in this case (e.g. algorithm by Joseph Kirk)

ai yu

very good

neha r


khld ab

chrystal Amutha


momo juju

hanan soliman

shankar velmurugan

good but need more comments to explain the m file

Brevetti Ge

I'm Italian...
what are "farthest..." , "...previous?"...
Help me, please...

Eyup Cinar

Good! but can be excellent with more comments and details inside the codes.It would be better to see more explanatory m file here.

Shahzada Rasool

good example, but farthestNextHop and PreviousHop should be explained

Joseph Kirk

This was very nice and I wanted to give it a 5, but when I changed the random state a couple times, the algorithm did not always find the shortest path... so I wonder if there is a bug that need to be fixed? (rand states = 1, 2, 4, 8 and 10 were the ones I checked that appeared to have an obviously shorter route than the one shown)

An Vincint

I appreciate it very much!

john bautista

very good

achilles boursianis

lydiah asere

samy jojo

not too bad

Alg Searcher

Babis Grouzakis

excellent work,i have to study it carefully,step by step.

sanith Wijesinghe

egis cioperiux

Andrew Wagner

Worked beautifully. Not sure what the last couple parameters are for, but they can be initialized according the the commented out usage example at the top of the file.

lili Woo

It is good that results are showed.

MATLAB Release
MATLAB 6.0 (R12)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video