# How can i get all paths between two nodes ??

104 views (last 30 days)
shaifali shakya on 23 Jan 2015
Commented: Image Analyst on 21 Jun 2020
How can i get all paths between two nodes
##### 2 CommentsShowHide 1 older comment
shaifali shakya on 24 Jan 2015
yes i have a matrix representing all paths between a set of nodes and i wish to find all paths between source and destination.

Kelly Kearney on 24 Jan 2015
If you're looking for the shortest paths, there are a few FEX entries that implement algorithms for this, including both depth-first and breadth-first searches. I use matlab_bgl, which includes several shortest path algorithms.
However, if you're really looking for all paths between two nodes, I found that algorithms for that are more scarce. I wrote pathbetweennodes.m to do just that... I wrote it for fairly small graphs (~50 nodes or fewer), so I'm not sure how efficient it might be for larger graphs, but it has worked well for my purposes.
##### 2 CommentsShowHide 1 older comment
Pham Minh Cong on 9 Mar 2020
Great work !
I am new to this subject, do you have a name for your algorithms ?

Image Analyst on 24 Jan 2015

Emad NB on 14 Dec 2018
You can use my function below. I use weight factor as a signal to find different pathes:
function pth=pathof(graph,startn,endn)
stop=0;
n=0;
while stop~=1
n=n+1;
Temp=shortestpath(graph,startn,endn);
eidx=findedge(graph,Temp(1:end-1),Temp(2:end));
if n~=1
if length(Temp)==length(pth{n-1,1})
if Temp==pth{n-1,1}
stop=1;
else
pth{n,1}=Temp;
graph.Edges.Weight(eidx)=100;
end
else
pth{n,1}=Temp;
graph.Edges.Weight(eidx)=100;
end
else
pth{n,1}=Temp;
graph.Edges.Weight(eidx)=100;
end
clear Temp eidx;
end
##### 2 CommentsShowHide 1 older comment
Image Analyst on 21 Jun 2020
Why not use bwdistgeodesic()? Your problem statement is exactly what Steve worked on. Did you overlook my answer with the link to his blog?
The above image is from part 5 of his blog series. Don't you think that pretty much describes your problem?