Unrecognized function or variable 'setupgraph'

조회 수: 9 (최근 30일)
lol
lol 2021년 11월 14일
댓글: Jan 2021년 11월 15일
I'm doing a Dijkstra' Algorithm.
And I have 2 scripts:
-This one is the one that I run:
-In this one I have the following code (which is all uploaded also):
%---------------------------------------------------
% Dijkstra Algorithm
% author : Dimas Aryo
% email : mr.dimasaryo@gmail.com
%
% usage
% [cost rute] = dijkstra(Graph, source, destination)
%
% example
% G = [0 3 9 0 0 0 0;
% 0 0 0 7 1 0 0;
% 0 2 0 7 0 0 0;
% 0 0 0 0 0 2 8;
% 0 0 4 5 0 9 0;
% 0 0 0 0 0 0 4;
% 0 0 0 0 0 0 0;
% ];
% [e L] = dijkstra(G,1,7)
%---------------------------------------------------
function [e L] = dijkstra(A,s,d)
if s==d
e=0;
L=[s];
else
A = setupgraph(A,inf,1);
if d==1
d=s;
end
A=exchangenode(A,1,s);
lengthA=size(A,1);
W=zeros(lengthA);
for i=2 : lengthA
W(1,i)=i;
W(2,i)=A(1,i);
end
for i=1 : lengthA
D(i,1)=A(1,i);
D(i,2)=i;
end
D2=D(2:length(D),:);
L=2;
while L<=(size(W,1)-1)
L=L+1;
D2=sortrows(D2,1);
k=D2(1,2);
W(L,1)=k;
D2(1,:)=[];
for i=1 : size(D2,1)
if D(D2(i,2),1)>(D(k,1)+A(k,D2(i,2)))
D(D2(i,2),1) = D(k,1)+A(k,D2(i,2));
D2(i,1) = D(D2(i,2),1);
end
end
for i=2 : length(A)
W(L,i)=D(i,1);
end
end
if d==s
L=[1];
else
L=[d];
end
e=W(size(W,1),d);
L = listdijkstra(L,W,s,d);
end
function G = exchangenode(G,a,b)
%Exchange element at column a with element at column b;
buffer=G(:,a);
G(:,a)=G(:,b);
G(:,b)=buffer;
%Exchange element at row a with element at row b;
buffer=G(a,:);
G(a,:)=G(b,:);
G(b,:)=buffer;
function L = listdijkstra(L,W,s,d)
index=size(W,1);
while index>0
if W(2,d)==W(size(W,1),d)
L=[L s];
index=0;
else
index2=size(W,1);
while index2>0
if W(index2,d)<W(index2-1,d)
L=[L W(index2,1)];
L=listdijkstra(L,W,s,W(index2,1));
index2=0;
else
index2=index2-1;
end
index=0;
end
end
end
which -all dijkstra
And the file that it runs, which is also uploaded, contains this:
But it has the following error:
And I don't know why, can you please help me?
  댓글 수: 2
DGM
DGM 2021년 11월 14일
That function is included with that FEX submission. Did you download all the files? Are they all on the path?
lol
lol 2021년 11월 14일
yes, I downloaded all

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

채택된 답변

Jan
Jan 2021년 11월 14일
You have mentiones the source of the dijkstra function in your other thread: https://www.mathworks.com/matlabcentral/fileexchange/36140-dijkstra-algorithm
Press the download button there to obtain all files of this submission including setupgraph.m and copy them to the same folder.
  댓글 수: 2
lol
lol 2021년 11월 15일
I already did, but now it appears this problem:
'dijkstra' is used in Calculate Number of Lines of Code by Using Report Information Object.
And I don't know why, can you please help me?
Jan
Jan 2021년 11월 15일
What do you do? How do you start this code?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dijkstra algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by