problem with stimulus presentation and key recording

Hi everyone,

Thanks for the help provided through this forum. This is my problem: I have something like this

%I generate two stimuli and a fixation cross and I present them simultaneously


% here is the first stimulus

 Screen('FillOval', w, [255 255 255], Stimulus1);


% here is my fixation cross

[X,Y] = RectCenter(scherm);

FixCross = [X-0.5,Y-20,X+0.5,Y+20;X-20,Y-0.5,X+20,Y+0.5];

Screen('FillRect', w, [255 0 0], FixCross');


%here is the second stimulus

Screen('FillOval', w, stimColor,sizesS);


% now the two stimuli are presented on the screen one on the left and one on the right with the fixation cross in the middle

onset = Screen('Flip',w,onset + (waitframes - 0.5) *1* ifi);


% The subjects has to make a decision between the two stimuli by pressing left or right and I record the key they press and reaction times

tStart = GetSecs;

    respToBeMade = true;

    while respToBeMade

        [keyIsDown,secs(i), keyCode(i)] = KbCheck;

        if keyCode(escapeKey)

            ShowCursor;

            sca;

            return

        elseif keyCode(leftKey)

            response = 1;

            respToBeMade = false;

        elseif keyCode(rightKey)

            response = 0;

            respToBeMade = false;

        end

    

    end

    

    

% Here are the reaction times

    tEnd = GetSecs;

    rt(j) = tEnd - tStart;




Now, my problem is that if I run the script, after I press a button for a response in the first trial I am presented with a trail that remains on the screen for few msecs and then another trial during which I can give a response. And then again, one trial flips fastly and a second one 'remains on the screen' so in the end I can collect only reaction times for half of the trials. Of course I want to collect reaction times for all trials and not only for one out of two! One thing I noticed is that if I change  the following code


% The subjects has to make a decision between the two stimuli by pressing left or right and I record the key they press and reaction times

tStart = GetSecs;

    respToBeMade = true;

    while respToBeMade

        [keyIsDown,secs(i), keyCode(i)] = KbCheck;

        if keyCode(escapeKey)

            ShowCursor;

            sca;

            return

        elseif keyCode(leftKey)

            response = 1;

            respToBeMade = false;

        elseif keyCode(rightKey)

            response = 0;

            respToBeMade = false;

        end

    

    end

    

    

% Here are the reaction times

    tEnd = GetSecs;

    rt(j) = tEnd - tStart;


simply with a more basic KbStrokeWait each trial is presented and I have to press a button to move to the other trial (but of course KbStrokeWait is not what I need to collect reaction times so I haven't solved my problem).

Any suggestion on how to solve this problem?


I hope my question is well formulated and clear.

Thank you in advance,


Joe


Your code is a little long to read, but sounds like the first key press is getting picked up more than once. kbstrokewait waits for the key to be released before continuing, and you need to, too. Or, add a fixed ISI between trials.

On Fri, Oct 10, 2014 at 2:02 PM, cohen.joe28@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:

Hi everyone,

Thanks for the help provided through this forum. This is my problem: I have something like this

%I generate two stimuli and a fixation cross and I present them simultaneously


% here is the first stimulus

Screen('FillOval', w, [255 255 255], Stimulus1);


% here is my fixation cross

[X,Y] = RectCenter(scherm);

FixCross = [X-0.5,Y-20,X+0.5,Y+20;X-20,Y-0.5,X+20,Y+0.5];

Screen('FillRect', w, [255 0 0], FixCross');


%here is the second stimulus

Screen('FillOval', w, stimColor,sizesS);


% now the two stimuli are presented on the screen one on the left and one on the right with the fixation cross in the middle

onset = Screen('Flip',w,onset + (waitframes - 0.5) *1* ifi);


% The subjects has to make a decision between the two stimuli by pressing left or right and I record the key they press and reaction times

tStart = GetSecs;

respToBeMade = true;

while respToBeMade

[keyIsDown,secs(i), keyCode(i)] = KbCheck;

if keyCode(escapeKey)

ShowCursor;

sca;

return

elseif keyCode(leftKey)

response = 1;

respToBeMade = false;

elseif keyCode(rightKey)

response = 0;

respToBeMade = false;

end

end

% Here are the reaction times

tEnd = GetSecs;

rt(j) = tEnd - tStart;




Now, my problem is that if I run the script, after I press a button for a response in the first trial I am presented with a trail that remains on the screen for few msecs and then another trial during which I can give a response. And then again, one trial flips fastly and a second one 'remains on the screen' so in the end I can collect only reaction times for half of the trials. Of course I want to collect reaction times for all trials and not only for one out of two! One thing I noticed is that if I change the following code


% The subjects has to make a decision between the two stimuli by pressing left or right and I record the key they press and reaction times

tStart = GetSecs;

respToBeMade = true;

while respToBeMade

[keyIsDown,secs(i), keyCode(i)] = KbCheck;

if keyCode(escapeKey)

ShowCursor;

sca;

return

elseif keyCode(leftKey)

response = 1;

respToBeMade = false;

elseif keyCode(rightKey)

response = 0;

respToBeMade = false;

end

end

% Here are the reaction times

tEnd = GetSecs;

rt(j) = tEnd - tStart;


simply with a more basic KbStrokeWait each trial is presented and I have to press a button to move to the other trial (but of course KbStrokeWait is not what I need to collect reaction times so I haven't solved my problem).

Any suggestion on how to solve this problem?


I hope my question is well formulated and clear.

Thank you in advance,


Joe



Thank you all for the very useful and helpful discussion! My script looks and works definitely better now,

Kind regards,

Joe