Unrecognized function or variable

8 ビュー (過去 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
  1 件のコメント
lol
lol 2021 年 11 月 13 日
thanks!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDijkstra algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by