Presenting oval for random duration in Psychtoolbox

How to Draw ‘oval’ for 50 ms for 5 times and 350 ms for 5 times “randomly”’. The total number of trials will be 10

Following code I have written in MATLAB, but i am not getting where I am making the mistake. Please do help me immediately regarding this. I would be grateful to you all. Thank You.

CODE WRITTEN IN MATLAB

% Clear the workspace and the screen
Screen('Preference', 'SkipSyncTests', 1);
sca;
close all;
clear;
% Delay_time is a variable that will take up 10 random values among 0.05s and 0.35s
Delay_time = zeros(1,10);
Delay_time (1:5) = 0.05;
Delay_time (6:10) = 0.35;
Delay_time = Delay_time (randperm(10));

% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);
% Get the screen numbers
screens = Screen('Screens');
% Draw to the external screen if avaliable
screenNumber = max(screens);
% Define black and white
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
% Open an on screen window
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
% Get the size of the on screen window
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
% Make a base Rect of 200 by 250 pixels
baseRect = [0 0 200 250];
% For Ovals we set a miximum diameter up to which it is perfect for
maxDiameter = max(baseRect) * 1.01;
% Center the rectangle on the centre of the screen
centeredRect = CenterRectOnPointd(baseRect, xCenter, yCenter);
% Set the color of the rect to red
rectColor = [1 0 0];

for i_trial = 1:10  
    % Draw the rect to the screen
    Screen('FillOval', window, rectColor, centeredRect, maxDiameter);
    % Flip to the screen
    Screen('Flip', window);
    WaitSecs (Delay_time (i_trial));
end

% Clear the screen
sca;

On the output screen, i see only one time oval is displayed. The loop is not working

You forgot to show an “empty screen” between ovals :

for i_trial = 1:10
% Draw the rect to the screen
Screen(‘FillOval’, window, rectColor, centeredRect, maxDiameter);
% Flip to the screen
Screen(‘Flip’, window);
WaitSecs (Delay_time (i_trial));
Screen(‘Flip’, window); % empty screen (nothing drawn in the backbuffer)
WaitSecs (1.0); % wait a bit
end
1 Like

Thanks a lot benoitberanger !! It’s working now

Also, using WaitSecs fot visual presentation timing is an invitation to poor timing. See our intro tutorials and demos on how to do proper visual timing with Screen('Flip') parameters.
-mario