Unrecognized function or variable
Afficher commentaires plus anciens


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 commentaire
lol
le 13 Nov 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Dijkstra algorithm dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!