Exit while loop and close screens after 10 mouse presses

I am using Psychtoolbox to design a fake experiment. I have all of the code correct, but I can't get it to close after 10 mouse clicks. I tried to start the whole thing with for i=1:10, with the actual code in a while loop under this for loop, but I don't know how to relate i with number of mouse clicks.
Thank you!

 채택된 답변

Stalin Samuel
Stalin Samuel 2015년 10월 24일
i = 0;
f = figure;
while i<11
w = waitforbuttonpress;
if w == 0
i =i+1;
if i ==10
close all;
break;
end
end
end

댓글 수: 3

Plausible.
You do not need the test for 10 because you have the "while i", which should be "while i < 10". Instead just have the "close all" after the "while".
The person posting the question in using a third party toolbox and might be planning to use its facilities to detect mouse presses; we need clarification about that.
I am using the psych toolbox. My code uses [x, y, b]= GetMouse to record the (x,y) coordinates of the cursor whenever the mouse is clicked. I would like to have the window close after 10 clicks have been recorded.
Then you can just use a for loop, since only one click will be registered for each iteration of the loop.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

질문:

2015년 10월 23일

댓글:

2015년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by