Subtract 1 from variable each second
古いコメントを表示
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?
採用された回答
その他の回答 (1 件)
Mathieu NOE
2021 年 6 月 10 日
hi
nothing fancy
counter = 100;
while true
do_something=true;
counter = counter -1; % decrement counter
pause(1); % 1 second pause
disp(counter);
end
3 件のコメント
Mathieu NOE
2021 年 6 月 10 日
so how do you plan to get the counter decremented every second ??
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!