被试内设计:自变量1(阶段:辨别学习阶段/反转阶段)*自变量2(框架:积极/消极)*自变量3(反馈程度:部分反馈/完全反馈) •总共有4组两两成对出现的图片,组合1为积极框架下完全反馈的刺激,组合2是积极框架下部分反馈的刺激,组合3是消极框架下完全反馈的刺激,组合4是消极框架下部分反馈的刺激,电脑会一左一右的呈现图片刺激,被试按“F”键代表选择左边,按“J”键代表选择右边。第一个Run为辨别学习阶段,选择pos_1和pos_3是高奖赏概率,选择neg_1和neg_3是高惩罚概率。第二个Run为反转阶段,选择pos_1和pos_3是低奖赏概率,选择neg_1和neg_3是低惩罚概率。且每种组合中的两张图片收入或损失情况是独立的,如一个trial中pos_1收入+10并不代表pos_2就一定+0。 %% This is a main function to call other functions %% step01: collect information of participants name=inputdlg('请输入姓名','被试姓名',[1 60],{'abc'}); ID=inputdlg('请输入编号','被试id',[1 60],{'101'}); gender=inputdlg('请输入性别,男1,女2','被试性别',[1 60],{'2'}); ID=str2num(char(ID)); gender=str2num(char(gender)); %% step02: creat a main window [wname,HC,VC,slack]=creat_mainwindow; %% step03: to get initial parameters [stim_w,exp_seq,RT,ACC,tn,stim_dur,j_dur,startK,redK,greenK]=predata(wname); %% step04: present instructions getready(startK,HC,VC,wname); %% step05: present stimuli t=GetSecs;%获取当前时刻 for i=1:tn [RT(i),ACC(i),t]=present_trial(t,wname,stim_w(exp_seq(1,i),exp_seq(2,i)),... exp_seq(2,i),stim_dur,j_dur(i),slack,redK,greenK); end %% step 06: save data to the disk abc=fix(clock); path=pwd; if gender==1 fidraw=fopen([path '\Data\stroop_' char(name) '_' num2str(ID) '_' num2str(abc(4)) '_' num2str(abc(5)) '_Male.txt'],'a'); elseif gender==2 fidraw=fopen([path '\Data\stroop_' char(name) '_' num2str(ID) '_' num2str(abc(4)) '_' num2str(abc(5)) '_Female.txt'],'a'); end fprintf(fidraw,'Date \t Name \t ID \t Gender \t Trial \t condition \t stim_id \t color_id \t RT \t ACC \t ITI \t \n'); collect_data(name,ID,gender,RT,ACC,exp_seq,tn,j_dur,fidraw); %% step07: close window Screen('CloseAll'); sca fclose('all'); 根据题目,修改以上的主函数编码以及修改step05部分的编码,Matlab
时间: 2024-04-03 19:34:14 浏览: 58
根据题目,以下是修改后的主函数编码和step05部分的编码:
主函数编码:
function main_function
% step01: collect information of participants
name=inputdlg('请输入姓名','被试姓名',[1 60],{'abc'});
ID=inputdlg('请输入编号','被试id',[1 60],{'101'});
gender=inputdlg('请输入性别,男1,女2','被试性别',[1 60],{'2'});
ID=str2num(char(ID));
gender=str2num(char(gender));
% step02: creat a main window
[wname,HC,VC,slack]=creat_mainwindow;
% step03: to get initial parameters
[stim_w,exp_seq,RT,ACC,tn,stim_dur,j_dur,startK,redK,greenK]=predata(wname);
% step04: present instructions
getready(startK,HC,VC,wname);
% step05: present stimuli
t=GetSecs;%获取当前时刻
for i=1:tn
% present trial for each condition
if exp_seq(1,i) == 1 % 辨别学习阶段
[RT(i),ACC(i),t]=present_trial_discrimination(t,wname,stim_w(exp_seq(1,i),exp_seq(2,i)),...
exp_seq(2,i),stim_dur,j_dur(i),slack,redK,greenK);
elseif exp_seq(1,i) == 2 % 反转阶段
[RT(i),ACC(i),t]=present_trial_reversal(t,wname,stim_w(exp_seq(1,i),exp_seq(2,i)),...
exp_seq(2,i),stim_dur,j_dur(i),slack,redK,greenK);
end
end
% step 06: save data to the disk
abc=fix(clock);
path=pwd;
if gender==1
fidraw=fopen([path '\Data\stroop_' char(name) '_' num2str(ID) '_' num2str(abc(4)) '_' num2str(abc(5)) '_Male.txt'],'a');
elseif gender==2
fidraw=fopen([path '\Data\stroop_' char(name) '_' num2str(ID) '_' num2str(abc(4)) '_' num2str(abc(5)) '_Female.txt'],'a');
end
fprintf(fidraw,'Date \t Name \t ID \t Gender \t Trial \t condition \t stim_id \t color_id \t RT \t ACC \t ITI \t \n');
collect_data(name,ID,gender,RT,ACC,exp_seq,tn,j_dur,fidraw);
% step07: close window
Screen('CloseAll');
sca
fclose('all');
end
辨别学习阶段的present_trial_discrimination函数编码:
function [RT,ACC,t]=present_trial_discrimination(t,wname,stim,condition,stim_dur,j_dur,slack,redK,greenK)
% present stimulus
Screen('FillRect',wname,stim(3:5),stim(1,:));
Screen('Flip',wname);
% record response
[keyIsDown,secs,keyCode]=KbCheck;
while ~keyIsDown % wait for response
[keyIsDown,secs,keyCode]=KbCheck;
WaitSecs('YieldSecs', 0.0001);
end
RT=secs-t;
if condition == 1 % 正确答案为左边
if keyCode(redK)
ACC=1;
elseif keyCode(greenK)
ACC=0;
end
elseif condition == 2 % 正确答案为右边
if keyCode(greenK)
ACC=1;
elseif keyCode(redK)
ACC=0;
end
end
% present feedback
if ACC == 1 % 正确
Screen('FillRect',wname,[0 255 0],stim(1,:));
elseif ACC == 0 % 错误
Screen('FillRect',wname,[255 0 0],stim(1,:));
end
Screen('Flip',wname);
WaitSecs(j_dur-slack);
end
反转阶段的present_trial_reversal函数编码:
function [RT,ACC,t]=present_trial_reversal(t,wname,stim,condition,stim_dur,j_dur,slack,redK,greenK)
% present stimulus
Screen('FillRect',wname,stim(3:5),stim(1,:));
Screen('Flip',wname);
% record response
[keyIsDown,secs,keyCode]=KbCheck;
while ~keyIsDown % wait for response
[keyIsDown,secs,keyCode]=KbCheck;
WaitSecs('YieldSecs', 0.0001);
end
RT=secs-t;
if condition == 1 % 正确答案为左边
if keyCode(redK)
ACC=1;
elseif keyCode(greenK)
ACC=0;
end
elseif condition == 2 % 正确答案为右边
if keyCode(greenK)
ACC=1;
elseif keyCode(redK)
ACC=0;
end
end
% present feedback
if ACC == 1 % 正确
Screen('FillRect',wname,[0 255 0],stim(1,:));
elseif ACC == 0 % 错误
Screen('FillRect',wname,[255 0 0],stim(1,:));
end
Screen('Flip',wname);
WaitSecs(j_dur-slack);
end
阅读全文