Reputation: 179
I have a matrix testNumbers = [1, 3, 8, 6, 9, 7]
.
What I want to do now is to make the user prompt a input and check if that input is equal to testNumbers(1)
, if it is do something (for later, %do something) and after 4 seconds continue to make the user input a number again but this time check if testNumbers(2)
is equal to the user prompt. This will then continue until the length(testNumbers)
has ended.
Can this be done? I assume a for loop has to be used, but I am totally new and therefore a example would be great. Then I can continue building this.
A example:
testNumbers = [1, 3, 8, 6, 9, 7]
Upvotes: 0
Views: 108
Reputation: 65430
You can use tic
and toc
to measure the elapsed time between two points. You can place the tic
before the user input (to start the timer), and then use a toc
wherever you want to check the time that has elapsed since that point. You can use multilple toc
's and they will all refer to the closest tic
.
% Start the timer
tic
% Prompt the user for input
value = input('Enter a number:');
elapsed_time = toc;
% If the response took more than 4 seconds
if elapsed_time > 4
disp('took too long')
end
If instead (as your title states) you want to wait 4 seconds, you can use pause
to pause execution of your program for a given amount of time
input('Enter a number:');
pause(4) % Pause for 4 seconds
% Do something else
Upvotes: 3