I have been tasked with creating a study where I need to alternate between three different screens for each 60 second trial.
The sequence goes: image 1 for 560ms, grey screen for 80ms, image 2 for 560ms and do this for either 60 seconds or until the participant presses a key to indicate that they have noticed a difference between the two images.
Right now I have the following function to decide which screen to display:
isRunning = true;
image = 1;
startTime = Screen('Flip',mainWin);
while isRunning
thisTime = Screen('Flip',mainWin);
image = timeToChangeImage(thisTime, startTime);
if image == 1
display image 1
elseif image == 2
display image 2
elseif image ==3
display image 3
if (thisTime - startTime) > 60
isRunning = false;
end
if (keyPressed)
isRunning = false;
end
end
function image = timeToChangeImage(time, startTime)
picOneIntervals = {[0, 560], [1200, 1760], [2400, 2960], [3600, 4160], [4800, 5360]};
greyIntervals = {[560, 640], [1760, 1840], [2960, 3040], [4160, 4240], [5360, 5440]};
picTwoIntervals = {[640, 1200], [1840, 2400], [3040, 3600], [4240, 4800], [5440, 6000]};
current time = (time - startTime) * 1000;
for interval = picOneIntervals
if current time >= interval{1}(1) && current time <= interval{1}(2)
image= 1;
end
end
for interval = greyIntervals
if current time >= interval{1}(1) && current time <= interval{1}(2)
image= 2;
end
end
for interval = picTwoIntervals
if current time >= interval{1}(1) && current time <= interval{1}(2)
image = 3;
end
end
end
This function has lists for the sub-intervals that each screen should be displayed within the trial. This is not a good solution though because I was first thinking that 6000ms was 60 seconds and this is obviously not the case so to use this solution for 60 seconds my lists for the intervals would all be 10 times longer.
So Iām wondering what a better way to program the ātimeToChangeImageā function would be. I need the function to tell the main while loop when to display each image. Or if there is a better way to program this within the while loop without using the function that would be good to know.
Thanks in advance for any help!