PTB通用RSVP实验范式无法运行

问题遇到的现象和发生背景

代码源于《心理学实验设计与编程指导手册》,输上MATLAB之后各种报错

问题相关代码,请勿粘贴截图
function runRSVP
%%清空屏幕
clear all;
close all;
sca;
Screen('Preference','SkipSyncTests',1);%忽略同步检测,某些设备才能正常运行。
%获取被试信息
subinfo=getSubInfo();%实验开始前,填写必要的被试信息。
%%实验的初始设置
textFlie='target.txt';%RSVP中目标文字提示,如不需要提示改为'none'
responseKeys={'y','n'};%反应键y=出现,n=未出现
randomizeStreams=1;%在RSVP中图片进行随机显示,如要顺序显示改为0
imageDuration=0.100;%在RSVP序列中,每个图像显示时间(秒)
backgroudColor=255;%RGB背景色黑色=0白色=255
textColor=0;%文字颜色黑色=0白色=255
imageFormat='jpg';%在实验中使用图片的格式(可以是.jpg.gif.png或.bmp)
timeBetweenTrials=1;%每个被试间等待时间(秒),如果为0直到被试按键才会开始下一个试次
rand('state',sum(100*clock));%初始化随机数的产生
%按键设置
KbName('UnifyKeyNames');
KbCheckList=[KbName('space'),KbName('ESCAPE')];
for i=1:length(responseKeys)
    KbCheckList=[KbName(responseKeys{i}),KbCheckList];
end
RestrictKeysForKbCheck(KbCheckList);%锁定按键,只有在KbCheckList中的按键才有效(即:空格键/ESC键/Y/N)
%屏幕设置%
screenNumber=max(Screen('Screens'));
[window,rect]=Screen('OpenWindow',screenNumber);
slack=Screen('GetFlipInterval',window);
scrW=rect(RectRight);
scrH=rect(RectBottom)
Screen(window,'FillRect',backgroudColor);
Screen('Flip',window);
%%设置刺激列表
%%获取实验用图片
imageFolder='images';%图像所在的文件夹名
f=dir(imageFolder);%遍历文件夹
folderList={};
for i=3:length(f)
if exist([imageFolder '/' f(i) .name],'dir')
folderList=vertcat(folderList,f(i).name);
end
end
nTrials=length(folderList);%试次等于images内文件夹数
%%载入文本文件(可选)
%如果设定了显示文字,载入文字。文字以换行键进行分隔
if strcmp(textFlie,'none')==0
    showTextItem=1;
textItems=importdata(textFile,'\n');
else
    showTextItem=0
end
%%实验结果文件的目标文件夹
resultsFolder='results';
%随机试次列表
randomizedTrials=randperm(nTrials);
%%运行实验
%设置字体大小为40
Screen('TextSize',window,40);
%试次开始前的提示语“按空格键开始”
textOnScr='Press the space bar to begin';
Screen('DrawText',window,textOnScr,(scrW/2)-400,(scrH/2),textColor);
Screen('Flip',window)
%等待被试按空格键开始试次
while 1
    [keyIsDown,secs,keyCode]=KbCheck;
if keyCode(KbName('space'))==1
break;
end
end
%%运行实验
epRes={'SubID','Image Folder','Trial','TestString','Order','Response','RT'};
for trial=randomizedTrials
%取得文件夹中的图片名
    fileList=dir([imageFolder '\' folderList {trial} '\' imageFormat]);
    nImages=length(fileList);
%随机在RSVP中显示的文件顺序
if randomizeStreams
       order=randpem(nImages);
else
    order=1:nImages;
end
%储存顺序信息
    orderStr=int2str(order(1));
for i=2:nImages
    orderStr=[orderStr '-' int2str(order(i))];
end
%读取图片,并放入缓存中
for i=1:nImages
    img=imread([imageFolder '/' folderList{trial} '/' flieList(order(i)).name]);
    imageDisplay(i)=Screen('MakeTexture',window,img);
%计算图片在屏幕中心显示的位置
    imageSize=size(img);
    pos(i,:)=[(scrW-imageSize(2))/2 (scrH-imageSize(1))/2 (scrW+imageSize(2))/2 (scrH+imageSize(1))/2];
end
%设置优先级为最高
    Priority(MaxPriority(window));
    Priority(2)
%在屏幕中央显示一个十字
    fixationDuration=0.5;%十字的显示时间(秒)
    crossLength=16;%16像素高
    crossWidth=16;%16像素宽
crossColor=0;%0=黑色 1=白色 RGB
Screen('FillRect',window,crossColor,[(scrW-crossLength)/2 (scrH-crossWidth)/2 (scrW+crossLength)/2 (scrH+crossWidth)/2]);
  Screen('FillRect',window,crossColor,[(scrW-crossWidth)/2 (scrH-crossLength)/2 (scrW+crossWidth)/2 (scrH+crossLength)/2]);
  tFixation=Screen('Flip',window);
%空白屏幕
  Screen(window,'FillRect',backgroudColor);
  Screen('Flip',window,tFixation+fixationDuration-slack,0);
%显示目标文字提示
if showTextItems%显示文字
    textString=textItems{trail};
    textDuration=2;%文字呈现时间(秒)
    Screen('DrawText',window,textString,(scrW/2)-100,(scrH/2),textColor);
    tTextdisplay=Screen('Flip',window);
    %清屏
    Screen(window,'FillRect',backgroundColor);
    Screen('Flip',window,tTextdisplay+textDuration-slack,0);
else
    textString='';
end
%显示图片序列
    Screen(window,'FillRect',backgroudColor);
    Screen('DrawTexture',window,imageDisplay(1),[],pos(1,:));
    flipTime=Screen('Flip',window);
for i=2:nImages
    Screen(window,'FillRect',backgroundColor);
    Screen('DrawTexture',window,imageDisplay(i),[],pos(1,:));
    filpTime=Screen('Flip',window,flipTime+imageDuration-slack,0);
end
  Screen(window,'FillRect',backgroudColor);
  startTime=Screen('Flip',window,flipTime+imageDuration-slack,0);
  %获取按键反应
  rt=0
  resp=0
  while 1
      [keyIsDown,secs,keyCode]=Kbcheck
      respTime=GetSecs;
      pressedKeys=find(keyCode);
%ESC键终止实验
if keyCode(KbName('ESCAPE'))==1
    Priority(0);
    clear all;
    close all;
    sca;
return;
end
%检查反应键
if~isempty(pressedKeys)
for i=1:length(responseKeys)
if KbName(responseKeys{i})==pressedKeys(1)
    resp=responseKeys{i};
    rt=respTime-startTime;%计算反应时
end
end
end
%一旦做出反应后退出循环
if rt>0
break;
end
end
%清屏
   Screen(window,'FillRect',backgroudColor);
   Screen('Flip',window,tFixation+fixationDuration-slack,0);
%储存实验结果
 epResSize=size(epRes);
 epRes(epResSize(1)+1,:)= {subinfo(1),imageFolder,trial,textString,orderStr,resp,rt};
%清除图像缓存
for i=1:nImages
    Screen('Close',imageDisplay(i));
end
%如果之前设置了由被试自己决定开始下一个被试的话,等待被试按空格键开始下一次试次
if timeBetweenTrials==0
    while 1
        [keyIsDown,secs,keyCode]=KbCheck;
if keyCode(Kbname('space'))==1
    break
end
    end
else
    waitSecs(timeBetweenTrials);
end
end
%%实验结束
Priority(0);%设置优先级回到普通
RestrictKeysForKbCheck([]);%释放锁定的键盘,让所有按键都有效
saveData(resultsFolder,subinfo,epRes);%让被试信息和实验结果进行保存
Screen(window,'Close');
close all;
sca;
questdlg('Experiment Finished! Thank you very Much!','Thank you!','Thank you!','Thank you!');
return;
end

运行结果及报错内容

出现多处未定义等问题

我的解答思路和尝试过的方法

修改过一些文件的读取路径 以及定义一些代码 但是程序总是无法成功运行

我想要达到的结果

能够完成注意瞬脱实验,RSVP能够正确呈现,得到有效数据

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。