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

조회 수: 1 (최근 30일)
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, 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:
% 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;

답변 (1개)

Chetan
Chetan 2023년 11월 16일
I understand you're working on a use case in MATLAB's Psychtoolbox, where you aim to display an oval on the screen for specified durations in a random order.
The issue seems to lie in how you're managing the screen updates and wait times. In Psychtoolbox, `Screen('Flip', window)` refreshes the screen, followed by `WaitSecs` to maintain the display for a certain duration.
You also need to clear the screen after each display. This can be achieved using `Screen('FillRect', window, black);` to fill the screen with the background color, followed by `Screen('Flip', window);` to update the screen.
Here's a revised portion of your code:
for i_trial = 1:10
Screen('FillOval', window, rectColor, centeredRect, maxDiameter);
Screen('Flip', window);
WaitSecs(Delay_time(i_trial));
Screen('FillRect', window, black);
Screen('Flip', window);
end
This should effectively clear the screen after each display.
I hope this helps!

카테고리

Help CenterFile Exchange에서 Image display and manipulation에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by