I'm trying to write a script which gets user input for a specified time interval. I wrote a simple script as below:
timeEllapsed=0;
Count=0;
while 1
tic
input('press enter');
timeEllapsed=timeEllapsed+toc;
Count=Count+1;
if(timeEllapsed>5)
break;
end
end
disp ('result is:')
disp(Count)
This script gets user input, when the time between first and last input less than 5 seconds. But this script waits indefinitely if user doesn't enter any input as expected. Is there any way to get user input for exactly given time interval? Thanks in advance!
Source : http://www.mathworks.com/matlabcentral/answers/96229-how-can-i-have-a-dialog-box-or-user-prompt-with-a-time-out-period
This is a self contained solution...
To run a 5 seconds timeout input, just write:
https://www.mathworks.com/matlabcentral/answers/95301-how-can-i-implement-a-timer-dependent-input-request-in-matlab