问题描述
我必须向我的参与者展示一系列视觉刺激,每个刺激都持续一定数量的帧。每个刺激都被编码为一个数字(在 stimuli_matrix 中报告),它应该持续的帧数在 stimframesvector 中报告。 stimuli_matrix 的行代表试验。
我的问题是在指定的帧数内没有显示刺激。作为替代方案,我尝试创建一个矩阵,其中包含:试验应持续的帧数和要呈现的刺激序列,我只获得了闪烁、不准确和错误的(时间方向)刺激呈现。您能否帮助我改进代码,使其显示指定数量的帧的刺激而不会闪烁?
这是代码
vbl = Screen('Flip',window);
ifi = Screen('GetFlipInterval',window);
Screen('Flip',window);
for righe=1:size(stimuli_matrix,1)
for prov=1:size(stimuli_matrix,2)
waitframes=1;
stimduration = .5;
begduration = 1;
rndnumb=rand;
jitter= (rndnumb-0.5)*0.1;
Jittered_stim = stimduration + jitter;
Jittered_beg = begduration + jitter;
% How long should the image stay up in frames
Stim_Frames = round(Jittered_stim / ifi);
% Duration in frames of trial start
Beg_Frames = round(Jittered_beg / ifi);
stimframesvector=ones(1,Stim_Frames);
indice=stimuli_matrix(righe,prov)
%stimframesvector1=stimframesvector(1)*1
[keyIsDown,secs,keyCode] = KbCheck;
if keyCode(escapeKey)
sca;
end
tic;
for frames=1:length(stimframesvector)
if indice==0
Screen('DrawLines',window,allCoords,linewidthPix,white,[xCenter yCenter],2);
Screen('Flip',[],1);
elseif indice == 1
Screen('DrawTextures',D1,allRects,0);
Screen('Flip',1);
elseif indice == 2
Screen('DrawTextures',C1,1);
elseif indice == 3
Screen('DrawTextures',B1,1);
elseif indice == 4
Screen('DrawTextures',A1,1);
elseif indice == 5
Screen('DrawTextures',H1,1);
elseif indice == 6
Screen('DrawTextures',G1,1);
elseif indice == 7
Screen('DrawTextures',F1,1);
elseif indice == 8
Screen('DrawTextures',E1,1);
end
end
Screen('Flip',vbl+(waitframes-0.5)*ifi);
stimvec2=stimframesvector %checking time
toc;
end
end
解决方法
我认为问题在于您没有指定何时您希望使用 Screen Flip
命令翻转刺激序列中的每个刺激。下面是一个简化的示例,它生成一系列具有随机颜色和随机帧时间间隔的椭圆。关键是每个 Screen Flip
命令都包含第三个参数,该参数指示应该呈现刺激的 Psychtoolbox 时间。
try
screenNum= max(Screen('Screens'));
[wPtr,wRect]=PsychImaging('OpenWindow',screenNum,0);
ifi = Screen('GetFlipInterval',wPtr);
number_stim = 10;
stimuli_colors = round(rand(number_stim,3) * 255);
frame_deltas = 15 + round(rand(number_stim,1) * 15);
% initial flip
[~,lastOnset] = Screen('Flip',wPtr);
for f = 1:number_stim
Screen('FillOval',wPtr,stimuli_colors(f,:),CenterRect([0 0,400,400],wRect));
[~,lastOnset + ((frame_deltas(f) - 0.5) * ifi));
end
sca;
catch e
sca;
rethrow(e)
end