Chelsea - you haven't said what your error is, only that you are trying to collect the keyboard input and that presumably it isn't working. Your code to write the data to file is fine (I can run it and it works well if all variables are initializes) but I did notice that the keyboard input of 's' or 'l' was not being written, only the ASCII equivalent. For example if,
block = 42;
trial = 23;
keyResp = 's';
RT = 400.3;
Then the data written to file as
If you want to see the character 's' instead of 115, then change the line that writes this variable to file from
fprintf(dataFile,'%d,', keyResp);
to
fprintf(dataFile,'%s,', keyResp);
This will ensure that the character/string will be written as
EDIT
In addition to the above comments on the output to the file, if the code is run using the Psychtoolbox the following error appears
An indexing expression on the left side of an assignment must have at least one subscript.
due to the line
[keyIsDown,secs, KbName()] = KbCheck;
The use of the brackets is causing the error, and a further problem will arise due to the third output parameter named KbName which conflicts with a function of the same name.
This line of code should be changed to
[keyIsDown,secs,pressedKeys] = KbCheck;
as pressedKeys is a matrix representing the count that each key is pressed. As we are only interested in the escape, 's', and 'l' keys, then the code that follows will need to be changed to
[keyIsDown,secs, pressedKeys] = KbCheck;
if pressedKeys(escapeKey)
ShowCursor;
sca;
return;
elseif pressedKeys(leftKey)
keyResp = 's';
respToBeMade = false;
elseif pressedKeys(rightKey)
keyResp = 'l';
respToBeMade = false;
end
Note that the removal of the response local variable which was used in the subsequent if statement. That code, has been put in to the above so that we initialize keyResp given the pressed key.
Try the above and see what happens!