0

我在带有 PsychToolBox 的 Matlab 中有一个名为 Assignment 的函数。此功能向参与者显示随机颜色,并要求参与者命名颜色并记录此数据。

函数应该将 2 个输出作为字符串返回给我

  1. 随机颜色的 rgb 代码,如:trial(1).color = [5 5 5]
  2. 对应于录音的矩阵。

我写了主要功能和颜色部分还可以,但我无法将录制功能集成到主要功能中。

在主函数中我使用这个字符串trial.data = recording(1,0,5) ,然后我写了一个名为“recording”的子函数

 function recording (wavfilename, voicetrigger, maxsecs)

    bla, bla 

    end

但是,主功能无法识别子功能。我在做一个逻辑错误吗?错误信息如下

错误:文件:assignment.m 行:40 列:27 意外的 MATLAB 表达式。

第 40 行 = trial.data = recording(1,0,5)

function ass8(trial) 

Screen('Preference', 'SkipSyncTests', 1)

ListenChar(2);


Screen('HideCursorHelper', 0, 0)

[myWin, rect]=Screen('OpenWindow',0,[128,128,128]);


    centerX=rect(3)/2;
    centerY=rect(4)/2;


for trial = 1:100

    Screen('TextSize', myWin, 30);
    Screen('TextFont', myWin, 'Times');
    [normBoundsRect, offsetBoundsRect] = Screen('TextBounds',myWin, 'What is the color of the rectangle?');
    Screen('DrawText', myWin, 'What is the color of the rectangle?', (centerX-(normBoundsRect(3)/2)),(centerY-(normBoundsRect(4)/2+150)), [0,0,0]);

    Screen('Flip', myWin)
    WaitSecs(1)% inter stimulus interval



    color = randi(255,1,3)
   while 1
    Screen('FillRect', myWin, color ,[583, 284, 783, 484])
%    [ (centerX-100), (centerY-100), (centerX+100),(centerY+100)]); 

    Screen('Flip', myWin)
    WaitSecs(3)

    trial.color = color % trial 'ın rengini belirtmesini söyledim


    trial.data = reco(1,0 5)% trial'ın ismi 1,  kayıt yapacağı süre ise 3 sn


    if Waitsecs(3)==1
        break; % Terminates the loop if the condition is                %  satisfied
    end

   end


    pause(.05);

%  [clicks, x, y, buttons] = GetClicks(myWin);
% 
% buttons=0;
% while ~buttons
%     [x, y, buttons] = GetMouse(myWin);
% end 
%     while 1
%         [x,y,buttons] = GetMouse(myWin);
%         if ~buttons(1)
%             break;
%         end
%     end





 Screen('CloseAll')
end
end





function  reco(wavfilename, voicetrigger, maxsecs)
% 
% AssertOpenGL;

if nargin < 1
    wavfilename = [];
end

if nargin < 2
    voicetrigger = [];
end

if isempty(voicetrigger)
    voicetrigger = 0;
end

if nargin < 3
    maxsecs = [];
end

if isempty(maxsecs)
    maxsecs = inf;
end


InitializePsychSound;


freq = 44100;
pahandle = PsychPortAudio('Open', [], 2, 0, freq, 2);


PsychPortAudio('GetAudioData', pahandle, 10);

PsychPortAudio('Start', pahandle, 0, 0, 1);

if voicetrigger > 0
    % Yes. Fetch audio data and check against threshold:
    level = 0;

    % Repeat as long as below trigger-threshold:
    while level < voicetrigger
        % Fetch current audiodata:
        [audiodata offset overflow tCaptureStart] = PsychPortAudio('GetAudioData', pahandle);

        % Compute maximum signal amplitude in this chunk of data:
        if ~isempty(audiodata)
            level = max(abs(audiodata(1,:)));
        else
            level = 0;
        end

        % Below trigger-threshold?
        if level < voicetrigger
            % Wait for a millisecond before next scan:
            WaitSecs(0.0001);
        end
    end


    else
    % Start with empty sound vector:
    recordedaudio = [];
end


s = PsychPortAudio('GetStatus', pahandle)


while ~KbCheck && ((length(recordedaudio) / s.SampleRate) < maxsecs)
    % Wait a second...
    WaitSecs(1);

    % Query current capture status and print it to the Matlab window:
    s = PsychPortAudio('GetStatus', pahandle);

    % Print it:
    fprintf('\n\nAudio capture started, press any key for about 1 second to quit.\n');
    fprintf('This is some status output of PsychPortAudio:\n');
    disp(s);

    % Retrieve pending audio data from the drivers internal ringbuffer:
    audiodata = PsychPortAudio('GetAudioData', pahandle);
    nrsamples = size(audiodata, 2);

    % Plot it, just for the fun of it:
    plot(1:nrsamples, audiodata(1,:), 'r', 1:nrsamples, audiodata(2,:), 'b');
    drawnow;

    % And attach it to our full sound vector:
    recordedaudio = [recordedaudio audiodata]; %#ok<AGROW>
end





PsychPortAudio('Stop', pahandle);

audiodata = PsychPortAudio('GetAudioData', pahandle);


recordedaudio = [recordedaudio audiodata];


PsychPortAudio('Close', pahandle);

if ~isempty(wavfilename)
    psychwavwrite(transpose(recordedaudio), 44100, 16, wavfilename)
end


fprintf('helal lan!\n');

ListenChar(2);


end
4

0 回答 0