4 x 4 Matrix on each visual field
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I am trying to create an imaginary 4 by 4 matrix on each visual field. so that i can draw 12 cirlces on each side. can someone please help me to draw the matrix
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; % 160, 100, originally set to 150
stimsize = 52;
nrows = 4;
ncolumns = 8;
ncells = nrows*ncolumns;
%  Building the grid
r = 1;
for i =  1:ncolumns
    for j  =   1: nrows
        xCoord(r) = ((i-ncolumns)+1)*cellsize + x_middle;
        yCoord(r) = ((j-nrows)+1)*cellsize + y_middle;
        r=r+1;
    end
end
maxjitter = (cellsize-stimsize);
for ii = 1:length(xCoord);
    hold on
    x_coordinate = xCoord(randperm(numel(xCoord),1))
    y_coordinate = yCoord(randperm(numel(yCoord),1))
    Screen('FillOval', window, [0 0 0], [x_coordinate y_coordinate x_coordinate y_coordinate]);
end
% Screen('FillOval', window, [0 0 0], [x_middle-160 y_middle-160 x_middle+160 y_middle+160]);
% Screen('FillOval', window, [0 0 0], [x_middle-320 y_middle-320 x_middle+320 y_middle+320]);
% Screen('FillOval', window, [0 0 0], [X Y X Y]);
Screen('Flip', window);
WaitSecs(3);   
Screen('CloseAll');
0 comentarios
Respuestas (1)
  Deepak
 el 8 de En. de 2025
        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.
0 comentarios
Ver también
Categorías
				Más información sobre Timing and presenting 2D and 3D stimuli en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

