Assign a default value to input() after a specific delay?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Rishik Ramena
2020년 12월 7일
편집: Rishik Ramena
2020년 12월 7일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!