How to randomly present stimuli a specific number of times

6 visualizaciones (últimos 30 días)
Hi, I am currently trying to randomly present a series of consonents as part of an N-back task. I have a folder in which I have stored the consonents as jpg. images. There are 21 consonents in the folder. For the task, there should be 48 letter presentations in one sequence. However, there are only 21 consonents in the alphabet. So I was wondering if there was a way in which I could ensure that my code allows me to present the stimuli 48 times. Currently my code only allows me to present each letter once, so I only have 21 trials in the sequence.
I have the following code;
d=21; %Number of images to load in is 21.
if d<1 || d>21 %A check to ensure that the correct number of images will be displayed.
disp('Error, the number of images loaded in out of range')
end
rts= (zeros(21, 1)); %rts is a 21 by 1 array of zeros
response=(zeros(21, 1)); % response is a 21 by 1 array of zeros
dirname= 'C:\Users\User\Documents\MATLAB\stimuli\'; %Location of stimuli
count= 0;
d=dir([dirname '*.jpg']);
for a =randperm(numel(d))% return scalar count of elements in matrix
%And randomly present the images under the variable of d.
a= imread(d(a).name); %read in images in desired folder
imshow(a) %show selected images
pause(2); %allow a 2 second pause between successive stimuli.
b= imread('FixationDot.jpg');% read in the fixation dot
imshow(b) %show the fixation dot between every letter
pause(0.5); %allow the fixation dot to remain there for 0.5 seconds
tic
count= count+1;
response(count)= (getkey()); %Gain user input and convert ASCII to char format
rts(count)= toc; %Record the time taken to produce a response from user
end
CH= char(response); %conver ASCII to underlying char elements
I appreciate any suggestions that anyone has, thank you.

Respuesta aceptada

Jeff Miller
Jeff Miller el 1 de Feb. de 2019
If you want to present 48 stimuli, you need to replace your line
for a =randperm(numel(d))
with something like this
for a =numstoshow
where numstoshow is a vector of 48 numbers, each of which is between 1 and 21. You'll have to work out exactly how you want to construct that sequence of 48 numbers, depending on how often and how closely you want the stimuli to repeat within the sequence. There would be presumably be some constraints on that for an N-back task, depending on exactly how you want that task to work.
  1 comentario
Walter Roberson
Walter Roberson el 2 de Feb. de 2019
You should also consider reading in all of the images ahead of time, since you know you are going to need to show them all and the setup is not time-sensitive but the presentation is time sensitive.
You should also have a look at the third party Psychtools (PTB) which has developed functions for precise presentation times and precise response timing.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by