for loop i doesn't increase
Mostrar comentarios más antiguos
Do you see the problem why the i doesn't increase after the loop from the for
heres the code where the i never increment :
borne_actuel = borne1;
borne_ideal = 0;
distance_ideal = 0;
distance_ideal_fin = distance;
distance2 = 0;
distance3 = 0;
borne_invoulu = 0;
borne_precedente = borne1;
while 1
for i = 1:150
distance2 = matrixDistance(borne_actuel,i);
distance3 = matrixDistance(i,borne2);
if (distance2 <= autonomie && i ~= borne_invoulu)
if (i == borne2)
borne_ideal = i;
break
elseif (distance2 >= distance_ideal && distance3 < distance_ideal_fin)
distance_ideal = distance2;
distance_ideal_fin = distance3;
borne_ideal = i;
end
end
end
if (distance_ideal == 0.0)
fprintf('Aucun chemin ideal\n');
break
end
%ajouter la borne actuel dans un tableau pour suivre le chemin
% tab.ajouter[borne_ideal];
% test tab
if (borne_ideal == borne_actuel)
borne_invoulu = borne_ideal;
end
fprintf('%g\n', borne_ideal);
borne_precedente = borne_actuel;
borne_actuel = borne_ideal;
if (borne_actuel == borne2)
%on est arrivere
fprintf('GoodJob\n');
break
end
borne_ideal = borne1;
end
end
3 comentarios
Image Analyst
el 22 de Mzo. de 2020
We can't run your code unless you tell us what borne, autonomie, distance and matrixdistance() are.
How do you know i is not incrementing? After the for loop, put a fprintf:
for i = 1:150
fprintf('i = %d\n', i);
Do you see anything in the command window? It sure would be a lot easier to debug if we could run your code.
Charles-Antoine Danis
el 22 de Mzo. de 2020
Charles-Antoine Danis
el 22 de Mzo. de 2020
Respuestas (0)
Categorías
Más información sobre Number Theory en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!