パターン刺激の応用で、"T"と”L”をランダムに配置します。
以下のサンプルでは10×10の100個のグリッドのうち、30箇所にだけ画像を呈示します。
そうすることで画像を重複させずにランダムに配置させることが可能です。
randpermを使っているところがポイントです。
function TandL_rand% 複数の"T"の中に、"L"が1つ含まれる。% TとLは任意の角度に回転した状態で呈示。% TとLをランダムに配置する。% 何かのキーを押したら終了try AssertOpenGL; ListenChar(2); %Matlabに対するキー入力を無効 %myKeyCheck; screenNumber = max(Screen('Screens')); %[win, rect] = Screen('OpenWindow', screenNumber, [255 255 0], [10 50 750 550]); [win, rect] = Screen('OpenWindow', screenNumber, [255 255 255]); %画面の中心座標 [centerX centerY] = RectCenter(rect); %実験プログラムを保存しているフォルダ内に T.jpg と L.jpg を準備しておくこと。 Tfile = 'T.jpg'; Lfile = 'L.jpg'; %画像の読み込み Tdata = imread(Tfile, 'jpg'); Ldata = imread(Lfile, 'jpg'); %画像サイズの幅が「列数」に相当し、 %画像サイズの高さが「行数」の相当する [Ty, Tx, Td] = size(Tdata); [Ly, Lx, Ld] = size(Ldata); Timagetex = Screen('MakeTexture', win, Tdata); Limagetex = Screen('MakeTexture', win, Ldata); %凝視点の線分座標 FixationXY=[-20, 20, 0, 0; 0, 0, -20, 20]; %水平方向のグリッドの数 HorizGridNum=10; %垂直方向のグリッドの数 VertGridNum=10; a=[1:HorizGridNum]; b=[1:VertGridNum]; [x,y]=meshgrid(a,b); GridWidth = 70; GridHeight = 70; %赤い凝視点の描画 Screen('DrawLines', win, FixationXY, 2, [255 0 0], [centerX, centerY]); order=randperm(HorizGridNum*VertGridNum); for cnt = 1:30 index = order(cnt); if index ~= 13 %凝視点部分(グリッドの13番目)は描画しない %描画する画像の左上のX座標 tmpX = (x(index)-1) * GridWidth + centerX - (GridWidth * HorizGridNum)/2 + (GridWidth - Tx)/2; %描画する画像の左上のY座標 tmpY = (y(index)-1) * GridHeight + centerY - (GridHeight * VertGridNum)/2 + (GridHeight - Ty)/2; if index == 7 %グリッドの7番目に"L"を呈示する Screen('DrawTexture', win, Limagetex, [], [tmpX tmpY tmpX+Lx tmpY+Ly], rand(1)*360); else Screen('DrawTexture', win, Timagetex, [], [tmpX tmpY tmpX+Tx tmpY+Ty], rand(1)*360); end; end; end; Screen('Flip', win); KbWait; sca; ListenChar(0);catch sca; ListenChar(0); psychrethrow(psychlasterror);end