How to pause execution of program until a keypress

조회 수: 414 (최근 30일)
Amit Kumar
Amit Kumar 2014년 3월 12일
댓글: Steven Lord 2016년 11월 30일
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.

채택된 답변

Sagar Damle
Sagar Damle 2014년 3월 12일
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

추가 답변 (2개)

nl2605
nl2605 2014년 3월 12일
the command 'pause'. It pauses the program until keypress.

Davide Rambusi
Davide Rambusi 2016년 11월 30일
is there a faster way? in my case, I have to run my code 200 times, and at some point, it gets really slow. I checked with the profile command, and it seems that pause could be the problem
  댓글 수: 1
Steven Lord
Steven Lord 2016년 11월 30일
A faster way to wait an arbitrary amount of time until the user presses a key? No.
If you show your code (perhaps as a new question) we may be able to offer suggestions how to improve the performance of your code and avoid whatever is causing your code to take more time with each iteration.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by