find all possible paths between 2 nodes using recursion in matlab

조회 수: 1 (최근 30일)
biswajita lenka
biswajita lenka 2011년 12월 29일
hi,i m trying to find all possible paths using recursion in matlab. the code for recurssion is as follows:
function[allpaths=findnodes(maxnodes,source,destination,path,marked)
all paths = [];
marked=[marked source];
if (source==destinstion)
allpaths=path;
disp(['path is::'num2str(allpaths)]);
return;
else
for v=1:maxnodes; //for all the neighbours of source node
if ~ismember(v,marked)
path=[path v];
allpaths=[allpaths (findnodes
(maxnodes,v,destination,path,marked))];
index=find(path==v);
path(index)=[];
else
allpaths=[path];
end;
end;
end;
but here the recursion is not working properly.
can anybody help me?
  댓글 수: 1
Andrew Newell
Andrew Newell 2011년 12월 29일
How exactly is it not working? Please format your code (see http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question).

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2011년 12월 29일
Do not use the term path for a variable, because this shadows a very important Matlab function.
The number of square brackets in the 1st line is unbalanced.
I assume you want "allpaths = [];" instead of "all paths = [];". Spaces do matter in Matlab.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by