Assign a default value to input() after a specific delay?
2 views (last 30 days)
Show older comments
Hi,
I'd like to assign a specific value or "cancel" the input() if user doesn't enter anything after a specific delay, and go back to the beginnig of the loop.
This is supposed to be a mental arithmetic task where people have to subtract 13 from 1022; then from the result, etc.; meaning if the answer is correct, user have to continue subtracting 13 from the result. If the answer is wrong or doesn't answer anything within 7.5s, then he comes back to 1022-13.
So, when user doesn't enter anything inside the input string within 7.5secs, I want the msg3 to show up and directly return to the begining of the loop 1022-13. But this happens only when user enters the response which means the input string waits forever...
How can I solve that?
I also have a version with GetEchoString since I'm using Psychtoolbox at the end. But this is a short version.
Thanks!
part_resp = input('1022 - 13 :');
pas = 13;
duration_max = 7.5;
msg1 = ['good answer'];
msg2 = ['wrong anwer'];
msg3 = ['time out!'];
count = 1022;
tic
while true
b = toc;
if part_resp == count-13 & (duration_max-b) > 0
count=count-13;
tic
disp(msg1)
part_resp = input([num2str(count) '-13 :']);
elseif (duration_max-b) == 0 || (duration_max-b) < 0
disp(msg3)
count = 1022;
tic
part_resp = input([num2str(count) '-13 :']);
else
count = 1022;
tic
disp(msg2)
part_resp = input([num2str(count) '-13 :']);
end
end
0 Comments
Answers (1)
Rishik Ramena
on 7 Dec 2020
Edited: Rishik Ramena
on 7 Dec 2020
The input function does not support the timeout feature yet. As a workaround you can create a figure with timers. An implementation is shown here.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!