File Exchange

image thumbnail

waitinput

version 1.0 (1.98 KB) by

WAITINPUT Prompt for user input, but no longer than t seconds.

0 Downloads

Updated

View License

%WAITINPUT Prompt for user input, but no longer than t seconds.
% output = WAITINPUT('Input something',t) gives the user the prompt in the
% text string and then waits for input from the keyboard by t seconds.
% R is the result. When user not specified s argument R will be a double,
% or if argument s i s eqal to 's', R will be a char. For other s
% argument function return an error.
% Function works only with alphanumeric characters.
%
% Example:
% waitinput('what is your name? ',10,'s')
%
% This function is inspired by Matlab INPUT function and GetKeyWait by
% Jos (10584) from File Exchange:
% http://www.mathworks.com/matlabcentral/fileexchange/8297-getkeywait
%
% See also INPUT, KEYBOARD.
%
% Copyright 2010 Grzegorz Knor

Comments and Ratings (6)

Grzegorz Knor

@Misaki Soma - you are too impatient programmer. Please give more time to the user for typing an input :) It turns out that function for time less than 1s is not able to initialize correctly all objects.

Misaki Soma

It didn't work well in boucles, I don't know why it stops when I do:
valCont =NaN;
t=1;
while (isnan (valCont))
valCont = waitinput(num2str(t),0.001,'s');
t = t+1;
end

mohammad

thanks a lot. works perfect!!!

mohammad

mohammad

Grzegorz Knor

In line 37 should be:
error('The third argument to WAITINPUT must be ''s'', or ''d''.')

Instead of:
error('The second argument to WAITINPUT must be ''s'', or ''d''.')

MATLAB Release
MATLAB 7.8 (R2009a)
Acknowledgements

Inspired by: getkey, GetKeyWait

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today