Psychtoolbox- 将信息写入日志文件

Psychtoolbox- writing out information into a log file

我是编程新手,正在尝试一些我发现的教程来熟悉 Psychtoolbox。该脚本提供了 20 个试验,其中一张愤怒或悲伤的脸将出现在屏幕的左侧或右侧(情绪和位置都是随机的)。然后用户按 's' 或 'a' 键进行响应。这 运行 没问题,但问题是将信息写入日志文件。出于某种原因,每当我使用当前代码 运行 脚本时,程序就会崩溃。任何人都可以提供的任何帮助将不胜感激!这是我的代码:

%Clear the screen 
clear all;

%Open the on screen window 
[window, rect] = Screen('OpenWindow', 0);

%Find the center of the screen 
[xCenter, yCenter] = RectCenter(rect);

%Create sad picture textures 
sadFaceData = imread('sadface.jpg');
[imageHeight, imageWidth, colorChannels] = size(sadFaceData);
sadFaceTexture = Screen('MakeTexture', window, sadFaceData);

%Create angry face textures 
angryFaceData = imread('angryface.jpg');
[imageHeight, imageWidth, colorChannels] = size(angryFaceData);
angryFaceTexture = Screen('MakeTexture', window, angryFaceData);

%Define coordinates of the images
distanceFromCenter = 100;
leftRect = [xCenter-distanceFromCenter-imageWidth, yCenter-imageHeight/2, xCenter-distanceFromCenter, yCenter+imageHeight/2];
rightRect= [xCenter+distanceFromCenter, yCenter-imageHeight/2, xCenter+distanceFromCenter+imageWidth, yCenter+imageHeight/2];

%Set up responses 
sad = KbName('s');
angry = KbName('a');

%Get the number of total trials and sad face trials 
nTrials = 0; 
correct = 0;
totalcorrect = 0;

%Loop for the number of trials 
while nTrials < 20

 %Random number of 1 or 2
 randomFaceNum = randi(2);
 randomRectNum = randi(2);

 %Loop determining face and location 
 if randomFaceNum == 1 && randomRectNum == 1
 Screen('DrawTexture', window, sadFaceTexture, [], leftRect);

 elseif randomFaceNum == 1 && randomRectNum == 2
 Screen('DrawTexture', window, sadFaceTexture, [], rightRect);

 elseif randomFaceNum == 2 && randomRectNum == 1
 Screen('DrawTexture', window, angryFaceTexture, [], leftRect);

 else
 Screen('DrawTexture', window, angryFaceTexture, [], rightRect);

 end
 [stimOnset] = Screen('Flip', window);

 %Wait for the key press
 [secs, keyCode] = KbStrokeWait; 
 response=KbName(keyCode);
 responseTime = secs - stimOnset;

 %Determine if the response was correct 
 if randomFaceNum == 1
      if response == 's'
           correct = 1;
      end
 else
      if response == 'a'
           correct = 1;
      end
 end

 totalcorrect = totalcorrect + correct;
 %Set up logfile where data will print to 
 fileName=strcat(subjectCode,'_log.txt');
 FID=fopen(fileName, 'a');
 fprintf(FID,'%d %d %d %s %.0f %d\n', nTrials, randomFaceNum,   randomRectNum,response, responseTime, correct);
 fclose(FID);

 nTrials = nTrials + 1;

 end

Screen('Close', window);

您发布的代码的问题是以下行使用字符串变量 'subjectCode' 来写入日志文件名,但该变量尚未定义:

 fileName=strcat(subjectCode,'_log.txt');

你可以添加例如

subjectCode = '1';

调用

之前的任何地方
fileName=strcat(subjectCode,'_log.txt');