I am modifying a previous experiment which drew a circle of concentric Gabor patches (an egg) among an array of distractor Gabors. In the previous version the egg could be drawn anywhere, but in this version, I am trying to constrain the placement of the egg to somewhere within a 4 degree window or outside of a 6 degree window, depending on the trial condition. To set specific limitations for different trial types, I thought that the ROI processing functions (drawcircles and inROI) might be a good way to create the central and peripheral windows. But I’ve recently come across some posts that suggest trying to mix the base MatLab drawing methods with Psychtoolbox can get very dicey (axes, timing, etc.), so I am trying to figure out a solution without undoing a lot of the original code. So far, the relevant sections of code look like this…
After all basic screen and stimulus set-ups, I limit the drawable screen space to avoid presenting pieces of the egg off-screen. This is leftover code from the previous experiment:
edgePadding = 0.5*ppd;
leftMostX = min([eggX.left eggX.right]);
rightMostX = max([eggX.left eggX.right]);
topMostY = min([eggY.left eggY.right]);
downMostY = max([eggY.left eggY.right]);
spaceRemainX = rect(3) - rightMostX - edgePadding;
spaceRemainY = rect(4) - downMostY - edgePadding;
minXOffset = round(-spaceRemainX); maxXOffset = round(spaceRemainX);
minYOffset = round(-spaceRemainY); maxYOffset = round(spaceRemainY);
Then I create the two ROI objects with drawcircle():
% Window radii in degrees
centralWindow = 4;
peripheralWindow = 6;
% ROI objects for central and peripheral conditions
eggCentral = drawcircle('Center',[centerX,centerY],'Radius',round(centralWindow*ppd),'Color','y');
eggPeripheral = drawcircle('Center',[centerX,centerY],'Radius',round(peripheralWindow*ppd),'Color','b'); %Color is for testing purposes only
eggPlace = {eggCentral, eggPeripheral};
Then I have a loop that generates the list of trial information (x,y coordinates for the egg’s center, egg jitter, egg tilt, etc.) which then feeds into the trial presentation loop. I use a while loop to randomly pick coordinates on the screen (reused from the old experiment) but I use inROI to test whether the coordinates are compatible with the condition in the trial list. inROI should be true for the central window condition (i.e., within the central ROI), and inROI should be false for the peripheral condition (i.e., outside the peripheral ROI). If neither of these conditions are met, then the while loop continues until a usable set of coordinates are found.
numExptBlocks = 1;
eggDirections = {'left', 'right'};
numReps = 1; %how many repeats of the combinations of these trial types per block
trialnum=0; trialList = struct;
for curRep = 1:numReps
for curEgg = 1:length(eggDirections)
for currEggPlace = 1:length(eggPlace) %
trialnum = trialnum+1;
%trial type info
trialList(trialnum).eggDirection = eggDirections{curEgg};
trialList(trialnum).contourJitter = contourJitter;
trialList(trialnum).eggPlacement = eggPlace{currEggPlace}; % (Ryan) Determine whether egg is central or peripherally placed
%egg drawing
trialList(trialnum).gaborAllLocs = critIndices;
startAngles = angles.(eggTypes{curEgg})(trialList(trialnum).gaborAllLocs );
%contourJitter (used to be a variable, but now a fixed parameter)
if contourJitter == 0
trialList(trialnum).angles = startAngles ;
else
polarityDecision = round(rand([1,length(startAngles)])) - 1; %will give us -1 and 0
toReplaceINDs = find(polarityDecision == 0);
polarityDecision(toReplaceINDs) = polarityDecision(toReplaceINDs) + 1;
trialList(trialnum).angles = startAngles + (polarityDecision*contourJitter);
end
%egg placement, offset from center of screen
% Sets eggXoffset and eggYoffset
% Checks to see if x and y of egg are within acceptable
% locaitons based on trial info of curEggPlace. If not, it
% reruns the eggXoffset and eggYoffset until it is acceptable.
eggPlaceOK = 0;
while eggPlaceOK == 0
trialList(trialnum).eggXOffset = randi([minXOffset maxXOffset]);
trialList(trialnum).eggYOffset = randi([minYOffset maxYOffset]);
tf = inROI(trialList(trialnum).eggPlacement,trialList(trialnum).eggXOffset,trialList(trialnum).eggYOffset);
% Lists the two conditions in which we would need to repeat
% the while loop continues, otherwise the coordinates are
% recorded and the loop finishes. Note that eggPeripheral
% is set to break when == 1. This is because the offset
% must be outside of the ROI.
if trialList(trialnum).eggPlacement == eggCentral && tf == 1
trialList(trialnum).trialEggCoord = [eggXOffset eggYOffset]; % (Ryan) Add this variable to results file
eggPlaceOK = 1;
elseif trialList(trialnum).eggPlacement == eggPeripheral && tf == 0
trialList(trialnum).trialEggCoord = [eggXOffset eggYOffset]; % (Ryan) Add this variable to results file
eggPlaceOK = 1;
end
end
end
end
end
I know this probably isn’t the most efficient way to get the best trial conditions, but I’ve kept it this way to avoid changing too much from the original code. More importantly, I was wondering if there was an alternative that would allow me to specify these two ROI objects or to limit the egg’s central coordinates in a way that would be compatible with PTB? Let me know if any additional trial presentation code will be helpful.