# Too many input arguments

3 views (last 30 days)
lol on 13 Nov 2021
Edited: dpb on 15 Nov 2021
I'm doing a Dijkstra' Algorithm.
And I have 2 scripts: -In this one I have the following code:
%---------------------------------------------------
% 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=;
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
And in the other script, I have the following code:
datos = xlsread('map.xlsx');%Reads the data from a file
[e, L] = dijkstra(datos, 1, 12);
Which have the following data (matrix): But when I run it (in the second script), it appears the following error: Can you please help me on what should I do?
dpb on 14 Nov 2021
Edited: dpb on 15 Nov 2021
As @Star Strider said, go to whomever/wherever it was you got these codes and ask/look for the missing routines there; we don't have any way to know anything about that.
The line
A = setupgraph(A,inf,1); %HERE IS ONE setupgraph
is trying to call the function called setupgraph; you need that function as well (plus any others that may be referenced later on in the code or called by it, of course).
We can't help with that...you got this code from somewhere else, there's the place to go for help with it.

Steven Lord on 14 Nov 2021
Do you need to implement Dijkstra yourself (as part of a homework assignment or school project) or do you just need to call some implementation of it? If the latter build a graph or digraph object from your data then call the shortestpath function on it. One of the methods available for use by the shortestpath function is the 'positive' algorithm whose description states it is "Dijkstra algorithm that requires all edge weights to be nonnegative."