使用 Psychtoolbox 呈现新的和随机的图像时出现问题

Troubles presenting new and random images using Psychtoolbox

我是编程新手,正在尝试使用 Psychtoolbox 编写我的第一个实验。在这个实验中,将显示随机数量的面孔(1-6 张面孔),每张面孔彼此不同。 2 秒后面部将消失,然后探测面将出现 2 秒。参与者必须决定探测面是否在前一组面中。使用我当前的代码,呈现的面孔数量是随机的。但我的问题是学习阶段显示的面孔总是相同的(例如,如果显示 5 张面孔,则在所有 5 个位置都是相同的面孔)。同样的面孔将出现 6 次试验(完成 p=1:6 for 循环),直到然后显示一张新面孔,但问题是相同的面孔一直出现。有没有办法让它每次都显示一张新面孔?

f = 1
ntrials = 20;
for i = 1:ntrials

  positions = Shuffle(1:6); %positions = the number of faces that will be shown (randomized)


           folder = '/Users/ricelab06/cropped_faces';
           fileFull = fullfile(folder, {'*.jpg'});
           files = dir(fileFull{1});
           images = cell(1, 1);  
           currentfilename = files(imgs(f)).name;
           fullFileName = fullfile(folder, currentfilename);
           currentimage = imread(fullFileName);
           images{imgs(f)} = currentimage;
           randFaceTexture = Screen('MakeTexture', window, currentimage);
           [imageHeight, imageWidth, colorChannels] = size(currentimage);

           f = f + 1;


for k = 1:6
     if positions(k) == 1  %1 face is shown 
         for p = 1:positions(k)             
                %Draw the images to the back buffer
                Screen('DrawTexture', window, randFaceTexture, [], []);

         end

     elseif positions(k) == 2 %2 faces are shown 
         for p = 1:positions(k)
                posLine = {line1, line2}; 
                %Draw the images to the back buffer 
                Screen('DrawTexture', window, randFaceTexture, [], [posLine{p}]);

         end

     elseif positions(k) == 3 %3 faces are shown 
         for p = 1:positions(k)
                posTriangle = {triangle1, triangle2, triangle3};                 
                %Draw the images to the back buffer
                Screen('DrawTexture', window, randFaceTexture, [], [posTriangle{p}]);

         end  

     elseif positions(k) == 4  %4 faces are shown 
         for p = 1:positions(k)
                posSquare = {square1, square2, square3, square4};                 
                %Draw the images to the back buffer
                Screen('DrawTexture', window, randFaceTexture, [], [posSquare{p}]);

         end

     elseif positions(k) == 5  %5 faces are shown 
         for p = 1:positions(k)
                posPentagon = {pentagon1, pentagon2, pentagon3, pentagon4, pentagon5};                      
                %Draw the images to the back buffer
                Screen('DrawTexture', window, randFaceTexture, [], [posPentagon{p}]);

         end      

     elseif positions(k) == 6  %6 faces are shown
         for p = 1:positions(k)
                posHexagon = {hexagon1, hexagon2, hexagon3, hexagon4, hexagon5, hexagon6};                       
                %Draw the images to the back buffer
                Screen('DrawTexture', window, randFaceTexture, [], [posHexagon{p}]);

         end 
     end     
end

Screen('Flip', window);
WaitSecs(2);

显示的是同一张脸,因为面索引的选择(定义为变量 'f')是在 k = 1:6 循环之外定义的。因此,'f' 的相同单个值将用于加载所有 k 值的图像纹理。

不清楚您总共有 6 张面部图像还是更大的一组。但是在你的 k = 1:6 循环中的每个 运行 上,你可以通过以下方式 select k 独特的面部索引:

n = 10; % unclear your actual value of total face images
% choose 'k' values out of 'n' (without replacement)
faces_to_display = ChooseKFromN(n, k);

然后,您可以通过将这些面部图像加载为纹理(或者 select 如果预加载,则从数组中获取纹理)来显示 'faces_to_display' 中面部的索引。

实际上,当 select 随机输入数据时,您还需要添加:

% reseed random number generatetor
ClockRandSeed()

到脚本顶部以确保随机数生成器 selects 在 运行s 之间的不同值。