MATLAB: How to pause execution of program until a keypress

haltMATLABpause

Hi, I have two parts in my Matlab program and I want to pause first part until keypress event by user. I searched to pause function and found waitforbuttonpress. However I do not know how to use it. Can anyone suggest a good method to pause until a keypress or a specific keypress (y or Y) etc.? Thanks.

Best Answer

Use function 'pause'. e.g.
a = 20;
b = 40;
disp('Press a key !') % Press a key here.You can see the message 'Paused: Press any key' in % the lower left corner of MATLAB window.
pause;
disp(a)
disp(b)
Just for information : If you want to terminate your MATLAB program abruptly,you can use 'Ctrl+C'
key combination.The same method is used to terminate a command in 'Command Prompt'.
Similar commands in Command Prompt and MATLAB-
pause,echo on,exit,ver