Assign a default value to input() after a specific delay?

4 ビュー (過去 30 日間)
BERANGERE VILLATTE
BERANGERE VILLATTE 2020 年 11 月 29 日
編集済み: Rishik Ramena 2020 年 12 月 7 日
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

回答 (1 件)

Rishik Ramena
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.

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by