Subtract 1 from variable each second
Ältere Kommentare anzeigen
Imagine I got something like this:
counter = 100;
while true
do_something=true;
pause(rand);
disp(counter);
end
Then I need the counter variable to get subtracted by 1 each second inside the while loop. Any suggestions?
Akzeptierte Antwort
Weitere Antworten (1)
Mathieu NOE
am 10 Jun. 2021
hi
nothing fancy
counter = 100;
while true
do_something=true;
counter = counter -1; % decrement counter
pause(1); % 1 second pause
disp(counter);
end
3 Kommentare
Mathieu NOE
am 10 Jun. 2021
so how do you plan to get the counter decremented every second ??
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!