for loop i doesn't increase
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Number Theory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!