필터 지우기
필터 지우기

Newbie: The variable (k) of the for loop inside a while

조회 수: 5 (최근 30일)
Sergio
Sergio 2013년 7월 17일
Hi
I have been programming for a short time with matlab and I have a question regarding this code:
for k=2:numel(UntitledCount)
if UntitledCount(k-1)~=UntitledCount(k)
while Voltage(k-11)<Voltage(k-10) && Voltage(k-11)<27
y=y+1;
k=k+1;
end;
topen=y*0.01;
topenarray(m)=topen;
m=m+1;
y=0;
end;
end;
The question is: The variable k, once has been increased during the while, when the condition of the while doesn't meet anymore, and it goes to the for loop again, the value of k remains the same before having been increased during the while loop or does it remain updated after the while?

채택된 답변

Iain
Iain 2013년 7월 17일
At the start/end of each for loop, the loop variable is reset to the next value.
for i = 1:5
disp(i)
i = i + 1;
disp(i)
end
Will produce
1
2
2
3
3
4
4
5
5
6

추가 답변 (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