Help for implementing timer function

I have an image containing L and T letters. My task is to show the image to the user and ask if the user could identify the letter L in the image. If the user presses Enter within 60 seconds, it means user can identify the letter. Then, a success message should be shown and the image must be displayed with the letter L in a different place. This process must continue for 10 times. However, if the user is not pressing enter in 60 seconds, the timer ends and a sound is played (say, sound1.wav) indicating wrong entry.
Iam having trouble implementing the timer function. Please help to complete this assignment.
This is the code I have so far:
clf;
for i = 1:10
image = imread("image5.jpeg");
imshow(image) %display the image with the letter L in a different place
user_input = input("Can you identify the letter L in the image? Press enter when you find it.");
if isempty(user_input)
disp("Success! The letter L was found.");
else
sound("input.wav");
disp("Letter L not found. Please try again.");
end
image = imrotate(image, i*36);
imshow(image)
pause(60);
end
Image:

댓글 수: 1

may use 'yes' or 'no' input from user (keys 'y' or 'n')
user_input = input("Can you identify the letter L in the image? Press (Y/N)");

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 1월 19일

0 개 추천

http://psychtoolbox.org/ is the recommended tool for that kind of work. It allows control over timing and detection of key presses

댓글 수: 4

Hi, thanks for the suggestion. Iam actually trying this on MATLAB online since I dont have the software. I was able to construct a possible solution. There is only one issue remaining. Iam not able to play the audio file in MATLAB file.
The code I used is:
function playSound(HObj, event)
disp("Letter L not found. Please try again.");
[y, Fs] = audioread("input1.wav");
sound(y, Fs);
end
I also tried a workaround, but it's still not working.
function playSound(HObj, event)
[y, Fs] = audioread("lover.wav");
disp("Letter L not found. Please try again.");
aObj = audioplayer(y, Fs, 16, 2);
aObj.play();
end
The argument '2' in audioplayer, I got it from running the following:
info = audiodevinfo;
disp(info.output.ID)
Please let me know If there is any way I can play the audio file. I would greatly appreciate it! Thanks.
Walter Roberson
Walter Roberson 2023년 1월 19일
When you use MATLAB Online you can only use sound if you are using the Chrome browser.
R Vaidehi
R Vaidehi 2023년 1월 20일
Yes, Iam using Chrome browser only.
Walter Roberson
Walter Roberson 2023년 1월 20일
Hmmm, I do not know. sound() is documented to work from Chrome (only) but it did not work on my test (from Mac)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Behavior and Psychophysics에 대해 자세히 알아보기

질문:

2023년 1월 18일

댓글:

2023년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by