Hello!
I am new at Psychtoolbox and MATLAB programming, and I was wondering if someone here could give me any advice regarding my question below.
I need to use two different setups occasionally 1) MATLAB 2018b with Psychtoolbox 3.0.16, Windows 7. 2) MATLAB 2019b with Psychtoolbox 3.0.16, Windows 10.
I am trying to create a task that presents four different images in random locations. The participant needs to choose the correct image through a touchscreen, and images should be located on the center to the bottom of the screen(excluding the top of the screen and far edges). I use the code that is down below, and for now, I get randomized images all over the screen except the far edges. Although I have managed to exclude the shapes that are located on the far edges, I still could not exclude the shapes that are located on the top of the screen. Appreciate it if someone could point out what is wrong?
for trialcount=1:nTrials
SetMouse(xCenter, yCenter, window); %initialise mouse at center position
% Randomize rect position along X and Y, normal distribution around
% bottom - center of the screen
rect1X= xCenter/2+randn*(screenXpixels/2);
rect1Y= yCenter/2+randn*(screenYpixels/2);
while(rect1X<200||rect1X>screenXpixels-200) %Check if located on the screen edges
rect1X= xCenter/2+randn*(screenXpixels/2);
end
while(rect1Y<200||rect1Y>screenYpixels-200) %Check if located on the screen edges
rect1Y= yCenter/2+randn*(screenYpixels/2);
end
while(1)
rect2X= xCenter/2+randn*((screenXpixels/2);
rect2Y= yCenter/2+randn*((screenYpixels/2);
if (rect2X<rect1X-200 || rect2X>rect1X+200 || rect2Y<rect1Y-200 || rect2Y>rect1Y+200) % Check no superposition
if ~(rect2X<200||rect2X>screenXpixels-200 || rect2Y<200 || rect2Y>screenYpixels-200) %Screen edges
break;
end
end
end
while(1)
rect3X= xCenter/2+randn*(screenXpixels/2);
rect3Y= yCenter/2+randn*(screenYpixels/2);
if (( rect3X<rect1X-200 || rect3X>rect1X+200 || rect3Y<rect1Y-200 || rect3Y>rect1Y+200)...
&&(rect3X<rect2X-200 || rect3X>rect2X+200 || rect3Y<rect2Y-200 || rect3Y>rect2Y+200)) % Check no superposition
if ~(rect3X<200||rect3X>screenXpixels-200 || rect3Y<200 || rect3Y>screenYpixels-200) %Screen edges
break;
end
end
end
while(1)
rect4X= xCenter/2+randn*(screenXpixels/2);
rect4Y= yCenter/2+randn*(screenYpixels/2);
if ((rect4X<rect1X-200 || rect4X>rect1X+200 || rect4Y<rect1Y-200 || rect4Y>rect1Y+200)...
&&(rect4X<rect2X-200 || rect4X>rect2X+200 || rect4Y<rect2Y-200 || rect4Y>rect2Y+200)...
&&(rect4X<rect3X-200 || rect4X>rect3X+200 || rect4Y<rect3Y-200 || rect4Y>rect3Y+200)) % Check no superposition
if ~(rect4X<200||rect4X>screenXpixels-200 || rect4Y<200 || rect4Y>screenYpixels-200) %Screen edges
break;
end
end
end
% Put unwanted shapes off screen
if ~(ismember('Square', shapes))
rect1X=screenXpixels/2+101;
rect1Y=screenYpixels/2+101;
end
if ~(ismember('Star', shapes))
rect2X=screenXpixels/2+101;
rect2Y=screenYpixels/2+101;
end
if ~(ismember('Triangle', shapes))
rect3X=screenXpixels/2+101;
rect3Y=screenYpixels/2+101;
end
if ~(ismember('Circle', shapes))
rect4X=screenXpixels/2+101;
rect4Y=screenYpixels/2+101;
end
rect1 = CenterRectOnPointd([0 0 150 150], rect1X, rect1Y)';
rect2 = CenterRectOnPointd([0 0 150 150], rect2X, rect2Y)';
rect3 = CenterRectOnPointd([0 0 150 150], rect3X, rect3Y)';
rect4= CenterRectOnPointd([0 0 150 150], rect4X, rect4Y)';
rects = [rect1 rect2 rect3 rect4]; %vector for all rects