Unrecognized function or variable

3 visualizaciones (últimos 30 días)
lol
lol el 13 de Nov. de 2021
Comentada: lol el 13 de Nov. de 2021
I'm doing a Dijkstra's Algorithm - Matlab Formulation. But when I run the code, it appears this error:
Unrecognized function or variable 'lenght'.
Error in dijkstra (line 5)
N = lenght(map);
Error in practice (line 2)
distances = dijkstra(map,1)
And I don't know why. It's worth mentioning that I have two windows or scripts, one where is my code and the definition of the functions, and the other one where I declare my data.
function distances = dijkstra(map,startingpoint)
N = lenght(map);
distances(1:N) = Inf;
visited(1:N) = 0;
distances(startingpoint) = 0;
while sum(visited) < N
%Find unvisited nodes
candidates(1:N) = Inf;
for index = 1:N
if visited(index) == 0
candidates(index) = distances(index);
end
end
%Find the one with the smallest distance value
[currentDistance, currentPoint] = min(candidates);
%Given the distance to the current point, update the distances to all
%its neighbors if the new distance will be smaller
for index = 1:N
newDistance = currentDistance + map(currentPoint, index);
if newDistance < distances(index)
distances(index) = newDistance;
end
end
%Mark the current node as visited
visited(currentPoint) = 1;
end
%The other window, has the following code:
map = xlsread('map.xlsx');
distances = dijkstra(map,1)
  1 comentario
lol
lol el 13 de Nov. de 2021
This is the error that prints (the window where I have declare the file and run the program is name "practice":
>> practice
Unrecognized function or variable 'lenght'.
Error in dijkstra (line 5)
N = lenght(map);
Error in practice (line 2)
distances = dijkstra(map,1)

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 13 de Nov. de 2021
Unrecognized function or variable 'lenght'.
% ^^ spelling mistake

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by