HOW TO USE FOR LOOP FOR MY PROGRAM

12 visualizaciones (últimos 30 días)
ANKIT MAURYA
ANKIT MAURYA el 20 de Dic. de 2021
Comentada: ANKIT MAURYA el 3 de Feb. de 2022
I want to display any image stored in my computer for 500 ms and after that there should be fixation cross for 500 ms on the screen. Till this point i have written the code but now i have to run the same sequence of stimuli for '10 times' using a for loop. Please help me with this. Even after knowing the syntax of for loop, i am unable to do this as i am very new to programming and matlab platform. Please help me precisely and in relation to my code written below. If possible please write the for loop code for me in relation to the code written below. I would be very grateful to you all for your suggestions. Thank You
Code:
% Clear the workspace and the screen
sca;
close all;
clear;
% 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);
% Query the frame duration
ifi = Screen('GetFlipInterval', window);
% Set up alpha-blending for smooth (anti-aliased) lines
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Setup the text type for the window
Screen('TextFont', window, 'Ariel');
Screen('TextSize', window, 36);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
Here we load in an image from file. This one is a image of rabbits that
% is included with PTB
theImageLocation = [PsychtoolboxRoot 'PsychDemos' filesep...
'AlphaImageDemo' filesep 'IIT.jpg'];
theImage = imread(theImageLocation);
% Get the size of the image
ankit = size(theImage);
% Make the image into a texture
imageTexture = Screen('MakeTexture', window, theImage);
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, imageTexture, [], [], 0);
% Flip to the screen
Screen('Flip', window);
% % Wait for two seconds
WaitSecs(1);
% KbStrokeWait;
% Here we set the size of the arms of our fixation cross
fixCrossDimPix = 20;
% Now we set the coordinates (these are all relative to zero we will let
% the drawing routine center the cross in the center of our monitor for us)
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
% Set the line width for our fixation cross
lineWidthPix = 4;
% Draw the fixation cross in white, set it to the center of our screen and
% set good quality antialiasing
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
% Flip to the screen
Screen('Flip', window);
% Wait for a key press
WaitSecs (1);
% KbStrokeWait;
% Clear the screen
sca;

Respuesta aceptada

Voss
Voss el 20 de Dic. de 2021
Maybe something like this would work:
% Clear the workspace and the screen
sca;
close all;
clear;
% 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);
% Query the frame duration
ifi = Screen('GetFlipInterval', window);
% Set up alpha-blending for smooth (anti-aliased) lines
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Setup the text type for the window
Screen('TextFont', window, 'Ariel');
Screen('TextSize', window, 36);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
% Here we load in an image from file. This one is a image of rabbits that
% is included with PTB
theImageLocation = [PsychtoolboxRoot 'PsychDemos' filesep...
'AlphaImageDemo' filesep 'IIT.jpg'];
theImage = imread(theImageLocation);
% Get the size of the image
ankit = size(theImage);
% Make the image into a texture
imageTexture = Screen('MakeTexture', window, theImage);
% Here we set the size of the arms of our fixation cross
fixCrossDimPix = 20;
% Now we set the coordinates (these are all relative to zero we will let
% the drawing routine center the cross in the center of our monitor for us)
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
% Set the line width for our fixation cross
lineWidthPix = 4;
for i = 1:10
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, imageTexture, [], [], 0);
% Flip to the screen
Screen('Flip', window);
% % Wait for two seconds
WaitSecs(0.5); % 500 ms, as stated
% KbStrokeWait;
% Draw the fixation cross in white, set it to the center of our screen and
% set good quality antialiasing
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
% Flip to the screen
Screen('Flip', window);
% Wait for a key press
WaitSecs (0.5); % 500 ms, as stated
% KbStrokeWait;
% Clear the screen
sca;
end
  5 comentarios
Voss
Voss el 27 de En. de 2022
@ANKIT MAURYA: What is the behavior you observe when you run this code, and how is that behavior different from what you expect?
ANKIT MAURYA
ANKIT MAURYA el 3 de Feb. de 2022
Benjamin, i would like to inform you that I am able to solve this query now. Adding a blank screen was missing ater displaying oval.
But many many thanks for your quick reply

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Platform and License en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by