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

2 次查看(过去 30 天)
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