Collect data from button response
古いコメントを表示
Hi, I'm trying to collect keyboard input, to save to a file (either "s" or "l" key...). Here is the code I have now. I had previously used "keyCode" in place of "KbName" in the while loop, but apparently that doesn't exist? (I have defined block and trial elsewhere). I can't seem to figure out what/where the error is? Thanks!
escapeKey = KbName('ESCAPE');
leftKey = KbName('s');
rightKey = KbName('l');
...
secs0=GetSecs;
respToBeMade = true;
while respToBeMade
[keyIsDown,secs, KbName()] = KbCheck;
if KbName('ESCAPE')
ShowCursor;
sca;
return
elseif KbName('s')
response = 1;
respToBeMade = false;
elseif KbName('l')
response = 0;
respToBeMade = false;
end
end
if(response=='1')
keyResp='s';
elseif(response=='0')
keyResp='l';
end
RT=secs-secs0; % Get reaction time
dataFileName='Data';
dataFile=fopen(dataFileName,'a');
if dataFile == -1
error('Error opening data file!');
end
fprintf(dataFile,'%d,', block);
fprintf(dataFile,'%d,', trial);
fprintf(dataFile,'%d,', keyResp);
fprintf(dataFile,'%d,', RT);
fprintf(dataFile,'\n');
fclose(dataFile);
ShowCursor
ListenChar(0);
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Timing and presenting 2D and 3D stimuli についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!