How to count if loops
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Helen Kelly
am 10 Okt. 2017
Bearbeitet: Helen Kelly
am 14 Okt. 2017
I have code that needs to count a loop.
while loopEnd<loopStart count=0 loopStart=1 loopEnd=6 while loopStart < loopEnd count = count + 1 loopStart = loopStart + 5
0 Kommentare
Akzeptierte Antwort
Christoph F.
am 10 Okt. 2017
count=0
loopStart=1
loopEnd=6
while loopStart < loopEnd
count = count + 1
loopStart = loopStart + 5
end
It looks like count gets set to zero any time this part of the code executes. count should probably be initialized earlier in the code.
0 Kommentare
Weitere Antworten (1)
KL
am 10 Okt. 2017
If I understand you correctly, the second while loop should be above and as Christoph says it should also be initialized before. For example,
x=1;
while x==1
%initilize those values here
count=0
loopStart=1
loopEnd=6
%go into the second while loop here
while loopStart < loopEnd
%%your other conditions here
%%...
%thenn the condition for grey and then increment count and loopStart
if FL==128 && BR==128 % grey part
motors (0,0)
pause (0.5)
motors (20,20)
pause (1.5)
count = count + 1
loopStart = loopStart + 5
end
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!