Azzera filtri
Azzera filtri

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

5 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Iain
Iain il 17 Lug 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by