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!