notification in case missing answer

1 回表示 (過去 30 日間)
Nicolò
Nicolò 2013 年 4 月 23 日
hi everyone, i have an other question on interaction between time and user: i want my code to give a message to user if he takes too much time to answer the question. ps.: this message has to be sent even if the user dosn't answer the question.
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 4 月 23 日
What method are you using to interact with the user?
Nicolò
Nicolò 2013 年 4 月 24 日
編集済み: Nicolò 2013 年 4 月 24 日
something like this
%EXAMPLE
%request name
Name = input('insert your name','s');
%if the answer not arrive in 10sec
fprintf ('sorry you had took much time');
end

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 24 日

その他の回答 (1 件)

Jan
Jan 2013 年 4 月 24 日
編集済み: Jan 2013 年 4 月 24 日
initial = now;
Name = input('insert your name','s');
if now - initial > 10 % seconds
fprintf('sorry you had took much time\n');
end
Perhaps a native speaker could give an advice: "Sorry, you have taken too much time" ???
[EDITED] Oh, perhaps you are looking for a time-out, which stops the waiting for the user input? This is not possible in the Matlab-level with the INPUT command. Even with a GUI like INPUTDLG this is not easy, because writing a message to an UICONTROL will collide with deleteing the message by a TIMER.
With using Java you can create a TIMER object, which emulates pressing the RETURN key after a certain time using the "Java robot" (use this term to search on undocumentedmatlab.com). This can stop INPUT automatically, but you need an additional flag to distinguish this pseudo-keypress from the real return key.
This method would have a dangerous side-effect: When a dialog window is opened e.g. from a long copy process from the operating system, pressing RETURN automatically could cause a desaster. Therefore I will not post the corresponding code.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by