MATLAB: FOR loop skipping to a particular iteration

for loop

for i=2:1:(length(time_c)-1)
if wheelpower_c(i)>= 0
propulsionpower(i)=propulsionpower(i-1)+wheelpower_c(i);
Regenpower(i)=Regenpower(i-1);
Brakeloss(i)=Brakeloss(i-1);
I(i)=(Voc-sqrt((Voc^2)-(4*R.*batterypower_city(i))))/(2*R);
Soc(i)=Soc(i-1)-(I(i)*DT/battery_capacity_C);
V(i)=Voc-R*I(i);
this a part of my for loop and i wanna check whether my conditions hold at i=576 can i skip to that particular iteration? Thank you
length(time_c)=1374

Best Answer

No. The closest you can get is to modify your
for i=2:1:(length(time_c)-1)
to
for i = 576
You should also consider putting in a conditional breakpoint. Go into the editor and find the line "if wheelpower_c(i)>= 0" and look on the left side of the line, to the narrow strip between the line number and the code edit area. Right click on the small dash there, and select conditional breakpoint. A box will pop up asking you for the condition: enter
if i == 576
and accept that. Then run your code. It will not skip to 576: it will execute all previous iterations. But then when 576 does come around, it will stop with a breakpoint, at which point you can examine variables and use the "Step" and "Step In" buttons to advance the code.