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

2 visualizaciones (últimos 30 días)
Sergio
Sergio el 17 de Jul. de 2013
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?

Respuesta aceptada

Iain
Iain el 17 de Jul. de 2013
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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by