Unrecognized function or variable

7 次查看(过去 30 天)
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 个评论
lol
lol 2021-11-13
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)

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2021-11-13
Unrecognized function or variable 'lenght'.
% ^^ spelling mistake

更多回答(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