我對Matlab很新,但真的想要改進。對於我的實驗,我想顯示參與者回答是/否的圖片,使用兩個不同的密鑰(f & g),然後顯示下一張圖片,並且重複如此之前。在MatLab中重複試驗
呈現圖片,使用密鑰的作品,但我不能得到它重複審判。因此我的問題是如何讓程序重複/循環我的試驗? 到目前爲止,我的代碼中是否存在錯誤,或者是否有其他代碼需要使用?
這是我到目前爲止的代碼
function try1_6()
cleanupObj= onCleanup(@() myCleanupFxn);
% PRETEST
% Initialize screen with black background
winID = Screen('openWindow',0, [0 0 0]);
%Parameter
backcol=255;
textcol=0;
% Load image file(s)
structimages= [];
TheImagesdir = dir('theImagesdir/*.jpg');
for i=1: length(TheImagesdir);
TheImages = imread(['theImagesdir/' TheImagesdir(i).name], 'JPEG');
% Get width and height
imageX = size(TheImages,2);
imageY = size(TheImages,1);
% Convert to texture
myTexture = Screen('MakeTexture', winID, TheImages);
% Set destination rectangle
destRect = [50 100 50+imageX 100+imageY];
%save to structure
structimages(end+1).filename=TheImagesdir(i).name;
structimages(end).destRect= destRect;
structimages(end).texture= myTexture;
end
%Make triallist
numberOfItems= [5]; %list of all possible items
Nrepeats=4;
Response=0;
TrialList=HH_mkTrialList({numberOfItems Response},Nrepeats);
%PRESENTATION
for trialnum=1:size(TrialList,1)
nitems = TrialList(trialnum,1);
Screen('FillRect', winID,backcol); % makes the screen blank
%displays text
DrawFormattedText(winID,'dkjfghaslkdfglksdjgfh','center','center',textcol);
Screen('Flip', winID)
HH_waitForKeyPress({'space'}); % waits for spacebar to be pressed
Screen('FillRect',winID,backcol);
Screen('Flip',winID);
WaitSecs(1);
%display picture
whichTheImages= randi(length(TheImagesdir)); % randomly selects image for directory
Screen('FillRect',winID,backcol);
Screen('DrawTexture', winID, myTexture, [], destRect);
Screen('Flip', winID);
HH_waitForKeyPress({'f','j'},5)
if resp==-1
break
end
TrialList(trialnum,4)= response; %records response
end
end
function myCleanupFxn()
Screen('CloseAll')
end
您忘記提及的一個非常重要的事情是,您正在使用[Psychtoolbox](http://psychtoolbox.org/)作爲屏幕內容。 – Setsu 2015-03-30 22:00:35
另外,請正確縮進您的代碼。 'try'和'for'塊的主體應該用製表符縮進。另外,不要把整個事情都包裝在一個巨大的'try'中。 – Setsu 2015-03-30 22:03:30
這不是一個完整的問題。'HH_mkTrialList'和'HH_waitForKeyPress'都是自定義方法,你沒有解釋他們做了什麼。請參閱[this](http://stackoverflow.com/help/how-to-ask)在本網站上發佈問題的指南。 – Setsu 2015-03-30 22:18:28