Nested FOR loop and presented word lists on screen - needed for a short term memory DRM expierment

Hi guys, hopefully someone may be able to help. 


Basically, I am planning to run an experiment using MATLAB with the Psychtoolbox plugin. I won't go into too many details, and just outline what i need MATLAB and Psychtoolbox to do for me.


I have 16 different word lists stored in a single text file. Each word list has 15 words.  So essentially it is arranged 15 rows x 16 columns as i understand it. I need MATLAB/Psychtoolbox to present the first row, word by word, and then ask participants to type in as many of the words as they can remember from that list within a certain time frame.  And following this, do the same with row 2, then row 3 etc....


I do have some MATLAB code to show which maybe entirely wrong, or may be close. But i am hoping someone may be able to help out.


Here is the code - apoligies if this takes up a lot of space on the page:


NumWords = 15; %Number of words to present

NumRows = 16;

NumCols = 15;

wordDelimiter=' ';

Duration = 1.5 ; %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 j = 1 : NumWords ; % outerloop is carried out 'NumRows' times, and for each of these the inner loop is carried out 'NumCols' times

     

    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');

    KbWait;

    WaitSecs(ISI);

  

end;


DrawFormattedText(win, 'Thank you. Press any key to exit.' , 'center', 'center' ); %Write word to screen

Screen(win,'Flip');% present to the screen

KbWait; %Wait for keyboard response


sca;% Screen Close All 


At the moment, this just runs through the text file without stopping, so just presents word after word until the end.


Any advice would be amazing


Best,


Niall


It sounds like your code is just presenting the word lists without ever stopping to receive input from the subject. So in your giant for loop, after you present a column of words, then have a section where the subject can type into the screen. You may need to make sure that you're receiving keyboard input at this point. The function "GetEchoString" might be of help with this: http://docs.psychtoolbox.org/GetEchoString

Sometimes it helps to draw out the logic of what you want your program to do before you start programming it. That way, it will be more clear to you how you need to structure your code.

Debbie Yee

On Sun, Oct 11, 2015 at 5:16 PM, nialltaylor24@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:

Hi guys, hopefully someone may be able to help.


Basically, I am planning to run an experiment using MATLAB with the Psychtoolbox plugin. I won't go into too many details, and just outline what i need MATLAB and Psychtoolbox to do for me.


I have 16 different word lists stored in a single text file. Each word list has 15 words. So essentially it is arranged 15 rows x 16 columns as i understand it. I need MATLAB/Psychtoolbox to present the first row, word by word, and then ask participants to type in as many of the words as they can remember from that list within a certain time frame. And following this, do the same with row 2, then row 3 etc....


I do have some MATLAB code to show which maybe entirely wrong, or may be close. But i am hoping someone may be able to help out.


Here is the code - apoligies if this takes up a lot of space on the page:


NumWords = 15; %Number of words to present

NumRows = 16;

NumCols = 15;

wordDelimiter=' ';

Duration = 1.5 ; %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 j = 1 : NumWords ; % outerloop is carried out 'NumRows' times, and for each of these the inner loop is carried out 'NumCols' times

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');

KbWait;

WaitSecs(ISI);

end;


DrawFormattedText(win, 'Thank you. Press any key to exit.' , 'center', 'center' ); %Write word to screen

Screen(win,'Flip');% present to the screen

KbWait; %Wait for keyboard response


sca;% Screen Close All


At the moment, this just runs through the text file without stopping, so just presents word after word until the end.


Any advice would be amazing


Best,


Niall



Hi,

Thanks for advice. I've had a further go at this, and can get it so that it breaks after each column - the problem is - this means it breaks after each individual word. 

I need it to run through and present 15 words one by one - so essentially every column of a row  - and then break and ask for participant response after the 15th word has been presented.  And following participant response, continue over the rest of the rows in the same fashion.

I don't want to keep bothering you with this, but do you have any other pieces of wisdom that may point me in right direction.

Best

Niall