How can I reiterate a vector in side for loop when a condition is satisfied ?
Afficher commentaires plus anciens
I want to reiterate the angle when the condition is met, I tried to explain the question via the code below. I want re-iterate the value of the angle of the outer for loop (when the condition is met), in inner for loop in all the next iterations, in other words fix the value of angle that determined in the outer for loop and make it taking in consideration in the inner for loop in all next iterations.
Thanks in advance.
v=2;% velocity is 2 m/sec
for kk=1:100
for j=1:1 % OUTER LOOP
PreviousselectAngle_Max = selectAngle_Max(j)
angles= [21 25 36 80 90];
RandomizeOverAngles=randperm(numel(angles))
for i=1:1:5 % INNER LOOP
selectAngle = angles(RandomizeOverAngles(i))
displ(i,:) = [cos(selectAngle).v,sin(selectAngle).v]; % displacement
if Y % Condition is satisfied
displ = [cos(PreviousselectAngle_Max).v,sin(PreviousselectAngle_Max).v]; % Here I want in this loop
% only re-iterate PreviousselectAngle_Max in the all next
% iterations.
X(i) =do some calculations
end
end
[max,idx]=max(X)
selectAngle_Max(j) = angles(RandomizeOverAngles(j))
Y = condition % X is a condition
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics 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!