How to pause a for loop until the enter key is pressed?

68 vues (au cours des 30 derniers jours)
Don
Don le 17 Nov 2015
Commenté : Don le 17 Nov 2015
For example, say I want to print the numbers from 1 to 10. I want it to wait until the enter key is pressed to print the next number.

Réponse acceptée

Kirby Fears
Kirby Fears le 17 Nov 2015
Use the pause command.
for ind = 1:10,
pause;
disp(ind);
end
In the command window, you will need to press any key to continue each time "pause" is reached.
Alternatively, you can use the input command which will be enter-key specific. Just replace pause with input('').

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by