Unrecognized function or variable

조회 수: 7 (최근 30일)
lol
lol 2021년 11월 13일
댓글: lol 2021년 11월 13일
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