Search code examples
matlabpsychtoolbox

Sequence of dots in matlab and psychotoolbox


How would i display one by one dots that are in a 3x3 matrix such as in the code below? I would like to have dot1 appears in position [x1,y1] of the grid for a time t1, then dot2 to appears in position [x2,y2] of the grid for a time t2. Only one dot is being shown at each time.

Thanks for help

%grid
dim = 1
[x, y] = meshgrid(-dim:1:dim, -dim:1:dim);
pixelScale = screenYpixels / (dim * 2 + 2);
x = x .* pixelScale;
y = y .* pixelScale;
% Calculate the number of dots
numDots = numel(x);
% Make the matrix of positions for the dots.
dotPositionMatrix = [reshape(x, 1, numDots); reshape(y, 1, numDots)];
% We can define a center for the dot coordinates to be relaitive to. 
dotCenter = [xCenter yCenter];
dotColors = [1 0 0];
dotSizes = 20;
Screen('DrawDots', window, dotPositionMatrix,...
dotSizes, dotColors, dotCenter, 2);

Solution

  • I think you want something like this?

    %positions of each successive dots:
    x_vec = [1,2,3,1,2,3,1,2,3];
    y_vec = [1,1,1,2,2,2,3,3,3];
    
    %wait times in sec for each dot:
    wait_times = [1,1,2,1,1,2,1,1,2]
    
    dotColor = [1 0 0];
    dotSize = 400;
    
    num_dots = length(x_vec);
    for i = 1:num_dots
    
        scatter(x_vec(i),y_vec(i),dotSize,dotColor,'filled');
        xlim([0,max(x_vec)])
        ylim([0,max(y_vec)])
        pause(wait_times(i));
    
    end