We can create a visual display with two 4x4 grids, one on each side of centre of the screen, representing the left and right visual fields, by using Psychtoolbox in MATLAB. We calculate the positions of these grids based on defined "cellsize" and "stimsize" parameters. Then, we randomly select 12 positions within each grid to draw circles using the "Screen('FillOval', ...)" function.
Below is the MATLAB code to achieve the same:
clc;
clear all;
close all;
rng('shuffle');
Screen('Preference', 'SkipSyncTests', 1);
[window, window_size] = Screen('OpenWindow', 0, [255 255 255], [], 32, 2);
x_middle = window_size(3) / 2;
y_middle = window_size(4) / 2;
cellsize = 160; % Size of each cell in the grid
stimsize = 52; % Size of each stimulus (circle)
nrows = 4;
ncolumns = 4; % 4x4 grid per visual field
ncells = nrows * ncolumns;
num_circles_per_side = 12; % Total circles to draw on each side
% Building the grid for left and right visual fields
xOffset = -x_middle / 2; % Offset for left visual field
yOffset = 0;
% Preallocate coordinates
xCoord = zeros(1, ncells * 2);
yCoord = zeros(1, ncells * 2);
r = 1;
for side = [-1, 1] % -1 for left, 1 for right
for i = 1:ncolumns
for j = 1:nrows
xCoord(r) = ((i - ncolumns / 2) * cellsize + x_middle + xOffset * side);
yCoord(r) = ((j - nrows / 2) * cellsize + y_middle + yOffset);
r = r + 1;
end
end
end
% Draw circles on each side
for side = 1:2 % 1 for left, 2 for right
indices = (1:ncells) + (side - 1) * ncells;
selected_indices = randperm(ncells, num_circles_per_side);
for idx = selected_indices
x = xCoord(indices(idx));
y = yCoord(indices(idx));
Screen('FillOval', window, [0 0 0], [x - stimsize / 2, y - stimsize / 2, x + stimsize / 2, y + stimsize / 2]);
end
end
Screen('Flip', window);
WaitSecs(3);
Screen('CloseAll');
Please find attached the documentation of functions used for reference:
I hope this helps in resolving the issue.
