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!