FOR loop skipping to a particular iteration

조회 수: 2 (최근 30일)
sairohith mudduluru
sairohith mudduluru 2018년 2월 19일
댓글: Walter Roberson 2018년 2월 19일
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
sairohith mudduluru 2018년 2월 19일
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