FOR loop skipping to a particular iteration

3 次查看(过去 30 天)
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
  3 个评论
sairohith mudduluru
its a dependency loop and i wanna run the loop automaticallyfor the first 575 values and debugg the 576th iteration can i do that?
Walter Roberson
Walter Roberson 2018-2-19
If you need to debug 576 then use the conditional breakpoint method.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-2-19
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by