我在编程上还很陌生,正在尝试使用Psychtoolbox编写我的第一个实验。在此实验中,将显示随机数量的面孔(1-6个面孔),并且每个面孔都彼此不同。这些面孔将在2秒钟后消失,然后出现一个探针面孔2秒钟。参与者必须确定探测面是否在先前的一组面中。使用我当前的代码,呈现的面孔数量正在随机化。但是我的问题是,学习阶段中显示的面孔始终是相同的(例如,如果显示了5张面孔,则在所有5个位置上都是相同的面孔)。相同的面孔将出现6次(完成循环时p = 1:6),直到显示出新面孔为止,但问题是相同的面孔始终出现。有没有一种方法可以使每次显示一张新面孔?
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);
答案 0 :(得分:0)
由于在k = 1:6循环之外定义了面部索引(定义为变量“ f”),因此显示了同一张面部。因此,相同的'f'值将用于为所有k值加载图像纹理。
尚不清楚您是否有6张面部图像或更大的图像集。但是在k = 1:6循环中的每次运行中,您都可以通过以下方式选择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);
然后,您可以通过将这些面部图像作为纹理加载(或从数组中选择纹理,如果预先加载),在“ faces_to_display”中显示这些面部的索引。
实际上,在随机选择数据时,您还需要添加:
% reseed random number generatetor
ClockRandSeed()
在脚本顶部,确保随机数生成器在两次运行之间选择不同的值。