matlab中的子功能

时间:2016-12-09 22:16:55

标签: string matlab function psychtoolbox

我在Matlab中使用PsychToolBox调用了Assignment函数。此功能向paritcipant显示随机颜色,并要求参与者命名颜色并记录此数据。

函数应该返回2输出为字符串

  1. 随机颜色的rgb代码,如:trial(1).color = [5 5 5]
  2. 与声音记录对应的矩阵。
  3. 我写的主要功能和颜色部分没关系,但我无法将录制功能集成到主功能中。

    主函数中的

    我使用这个字符串trial.data = recording(1,0,5) 然后我写了一个名为"记录"

    的子功能
     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
    

0 个答案:

没有答案