How to convert from a for loop to a while loop

1 view (last 30 days)
Hi there,
I need to modify the set of codes below to a while loop, but are sturggling to.
for k = 2:length(vecTime)
currentTime = vecTime(k);
currentDragCoeff = getDragCoeff(currentTime,tParaDeploy,dragAir,dragPara);
% To be completed in lecture
vecSpeed(k) = vecSpeed(k-1) + (g - currentDragCoeff/mass*vecSpeed(k-1))*dt;
vecHeight(k) = vecHeight(k-1) - vecSpeed(k-1)*dt;
end
Your help is much appreciated

Answers (1)

Walter Roberson
Walter Roberson on 29 Oct 2015
for K = A : B
some statement
end
is (except for odd cases) equivalent to
K = A;
while K <= B
some statement
K = K + 1;
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!