The following is an experimental stimulus I wrote about working memory. I have the experimenter five consecutive numbers to see if there were any answers. A total of 60 rounds, one round two questions
I want to join now when the experimenter does not answer within two seconds and automatically jumps to the next question, or the next turn and judges the question as an error. How can I start? Thank you~
% function wm5d_ntu(sub_name,run)
% working memory 5 digits keyboard;
close all;clear all;clc;
sub_name ='LHY';
run = 1;
trial =60;
% Here we call some default settings for setting up Psychtoolbox 在這裡,我們調用一些默認設置來設置Psychtoolbox
PsychDefaultSetup(0);
screens = Screen('Screens');
screenNumber = max(screens);
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black ,[0 0 900 900]);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
[xCenter, yCenter] = RectCenter(windowRect);
ifi = Screen('GetFlipInterval', window);
numSecs = 1;
numFrames = round(numSecs / ifi);
numFrames_cross = round(1.2 / ifi);
numFrames_black = round(0.2 / ifi);
numFrames_question = round(1 / ifi);
waitframes = 1;
TrueKey = KbName('M');
FalseKey = KbName('C');
%=====================trial random matrix=================
d10_mat = nchoosek(1:10,5); % 10 digit matrix
d10_mat_shf = Shuffle(d10_mat,2);
d10_mat_60 = d10_mat_shf(1:trial,:);
d10_mat_60_shf = d10_mat_60;
for i = 1:size(d10_mat_60,1)
idx = randperm(size(d10_mat_60,2));
d10_mat_60_shf(i,idx) = d10_mat_60(i,:);
end
tri_mat = d10_mat_60_shf;
tri_mat(tri_mat==10) = 0; % final trial matrix
%================question random matrix==========
q_logic = Shuffle([ones(trial/2,2);zeros(trial/2,2)]); %True=1, False=0
q_mat = q_logic;
for i = 1:size(q_logic,1) %trial
for q = 1:size(q_logic,2) %question
if q_logic(i,q) == 1 && q==1
idx = randperm(3);
q_mat(i,q) = tri_mat(i,idx(1));
elseif q_logic(i,q) == 1 && q==2
idx = randperm(3)+1;
q_mat(i,q) = tri_mat(i,idx(1));
if q_mat(i,1) == q_mat(i,2)
q_mat(i,q) = tri_mat(i,idx(2));
end
elseif q_logic(i,q) == 0 && q==1
d10 = 1:10;
inv_d5 = d10( ~ismember(1:10,d10_mat_60_shf(i,:)) );
tri = inv_d5(randperm(5));
tri(tri==10) = 0;
q_mat(i,q) = tri(1);
elseif q_logic(i,q) == 0 && q==2
d10 = 1:10;
inv_d5 = d10( ~ismember(1:10,d10_mat_60_shf(i,:)) );
tri = inv_d5(randperm(5));
tri(tri==10) = 0;
q_mat(i,q) = tri(1);
if q_mat(i,1) == q_mat(i,2)
q_mat(i,q) = tri(2);
end
end
end
end
q1_counter = 0;
q2_counter = 0;
rsptime_list = zeros( size(q_mat,1), size(q_mat,2));
rspkey_list = zeros( size(q_mat,1), size(q_mat,2));
for i = 1:size(tri_mat,1) %trial
%if i == 1
% DrawFormattedText(window, 'Name the color \n\n Press Any Key To Begin',...
% 'center', 'center', black);
% Screen('Flip', window);
% KbStrokeWait;
%end
tblack = GetSecs;
vbl = Screen('Flip', window);
for frame = 1:numFrames_black
% Color the screen red
Screen('FillRect', window, black);
% Flip to the screen
% vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end
GetSecs-tblack
tcross = GetSecs;
vbl = Screen('Flip', window);
for frame = 1:numFrames_cross
Screen('TextFont', window, 'Times New Roman');
Screen('TextSize', window, 150);
[xCenter, yCenter] = RectCenter(windowRect);
fixCrossDimPix = 60;
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
lineWidthPix = 4;
Screen('DrawLines', window, allCoords,...
lineWidthPix,white, [xCenter yCenter], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end
GetSecs-tcross
for j = 1:size(tri_mat,2) %digit number
tblack = GetSecs;
vbl = Screen('Flip', window);
for frame = 1:numFrames_black
Screen('FillRect', window, black);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end
GetSecs-tblack
t1 = GetSecs;
vbl = Screen('Flip', window);
for frame = 1:numFrames
line1 = '\n';
line2 = '\n ';
line3 = ['\n' num2str(tri_mat(i,j))];
line4 = '\n ';
line5 = '\n';
Screen('TextSize', window, 150);
DrawFormattedText(window, [line1 line2 line3 line4 line5],...
'center', screenYpixels * 0.12, white);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end
GetSecs-t1
t2 = GetSecs;
end
for q = 1:2
respToBeMade = true;
tResponse = GetSecs;
if q == 1
%io64( ioObj2, lpt2,1) ;
WaitSecs(.001);
%io64( ioObj2, lpt2,0);
elseif q ==2
%io64( ioObj2, lpt2,2) ;
WaitSecs(.001);
%io64( ioObj2, lpt2,0);
end
while respToBeMade == true
for frame = 1:numFrames_question
line1 = ['\n Question' num2str(q)];
line2 = '\n ';
line3 = ['\n' num2str(q_mat(i,q))];
line4 = '\n';
line5 = '\nN Y';
Screen('TextSize', window, 150);
DrawFormattedText(window, [line1 line2 line3 line4 line5],...
'center', screenYpixels * 0.12, white);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
GetSecs-t2
[keyIsDown,secs, keyCode] = KbCheck;
if keyCode(TrueKey)
response = 1;
respToBeMade = false;
rsptime_list(i,q) = GetSecs-tResponse;
rspkey_list(i,q) = 1;
elseif keyCode(FalseKey)
response = 0;
respToBeMade = false;
rsptime_list(i,q) = GetSecs-tResponse;
rspkey_list(i,q) = 0;
end
%resp=0;
%s=tResponse;
%s0=2;
%while (s-s0<2),respToBeMade == False;
% resp = io64(ioObj1,lpt1); %1:kbData(97)=1; 2:kbData(98)=2...
%RT=s-s0;
%end
end
end
if q == 1 && q_logic(i,q) == response
q1_counter = q1_counter+1;
num2str(q1_counter*100/i);
disp(['Correct! Q1 accuracy:' num2str(q1_counter*100/i) '%']);
elseif q == 2 && q_logic(i,q) == response
q2_counter = q2_counter+1;
num2str(q2_counter*100/i);
disp(['Correct! Q2 accuracy:' num2str(q2_counter*100/i) '%']);
elseif q == 1 && q_logic(i,q) ~= response
num2str(q1_counter*100/i);
disp(['Incorrect! Q1 accuracy:' num2str(q1_counter*100/i) '%']);
elseif q == 2 && q_logic(i,q) ~= response
num2str(q2_counter*100/i);
disp(['Incorrect! Q2 accuracy:' num2str(q2_counter*100/i) '%']);
end
end
end
Priority(0);
clear mex