Nested FOR loop with Psychtoolbox - Psychology memory experiment

7 views (last 30 days)
Hi, I am entirely new to MATLAB and am running into a couple of issues.
I essentially need MATLAB/Psychtoolbox to present 16 separate word lists, which contain 15 words each ( A total of 240 words). The word lists are read in via text file which has them stored in a 16 x 15 format - So each row is equal to a word list. What i need to happen is as follows; Have each word list (15 words in a row) presented on screen word by word -> after the first word list (basically row 1) has been presented, I need to break and have participants do a recall test by typing in as many of the words from that list as they can remember over a 1 minute period, and save their responses to an output file-> following this, I need the loop to repeat on the second word list (row 2) and continue like this until all 16 word lists (rows) have been presented along with the recall test for each.
At the moment I have created this nested FOR loop, which currently just runs through all of the rows 1, by 1, without stopping. I can't manage to get to stop at the end of each row. Here is the code:
NumWords = 240; %Number of words to present
NumRows = 16;
NumCols = 15;
wordDelimiter=' ';
Duration = 0.1 ; %Duration of presentation
ISI = 0.1; %Inter stimulus interval
X = 1366; %Screen resolution
Y = 768;
InputFile = 'Exp_1_studylist_A.txt'; %Open and read in word file
fileID = fopen(InputFile);
Words = textscan (fileID , '%s');
fclose(fileID);
Screen('Preference', 'SkipSyncTests', 2 ); %Setup psychotoolbox
win = Screen('OpenWindow',0,[],[0,0,X,Y]); %Open window
%Set text etc
Screen('TextSize',win, 24 );
Screen('TextFont',win,'times');
Screen('TextStyle', win, 0);
DrawFormattedText(win, 'Press any key to start.' , 'center', 'center' ); %Write word to screen
Screen(win,'Flip');% present to the screen
KbWait; %Wait for keyboard response
for i = 1 : NumRows ;
for j = 1 : NumWords ; %
DrawFormattedText(win, Words{1}{j}, 'center', 'center' ); %Write word to screen
Screen(win,'Flip');% present to the screen
WaitSecs(Duration);
Screen('FillRect', win ); %clear Screen
Screen(win,'Flip');
WaitSecs(ISI);
end
DrawFormattedText(win, 'Type as many of the words from the list as you can remember.' , 'center', 'center');
Screen(win,'Flip');
KbWait; %This is where we want participants to have 1 minute to do recall test
end;
I'm aware this is actually quite a simple program to make, I am just going in circles at the moment it seems.
Any advice would be amazing, and apologies if people have seen similar posts to this.
Kind Regards
Niall

Answers (0)

Community Treasure Hunt

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

Start Hunting!