How can i repeat my trial?

5 views (last 30 days)
myrte druyvesteyn
myrte druyvesteyn on 1 Apr 2015
Commented: Stephen23 on 2 Apr 2015
i'm very new to matlab ( first time project) so naturally i came across some problems. For my experiment i want to show a picture which the participant response yes/no to, using two different keys (f&g) and then the next picture is presented and it repeats so onward.
i so far managed to get 1 picture displayed and the key press works. however the next trial doesn't not open. thus my question what do i need to change or add so that the next picture ( and the next again) will open?
this is my code so far:
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
  4 Comments
per isakson
per isakson on 1 Apr 2015
Edited: per isakson on 1 Apr 2015
Yes, but you cannot assume that many persons here know about the "Psychophysics Toolbox". I don't. You might put the name of the toolbox in the title of your question to catch the eye of someone, who is able (and interested) to answer.
Stephen23
Stephen23 on 2 Apr 2015
@myrte druyvesteyn: Your current question title "How can i repeat my trial?" is so general that it could apply to almost any research that might be analysed using MATLAB. You should edit your question and make the title more attractive to those people who might know about the "Psychophysics Toolbox".

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!