CodeGuy
CodeGuy

Reputation: 28905

Basic sound error in Matlab

I have the following Matlab function to produce a sound:

function [] = makesound( )

    cf = 2000;                  % carrier frequency (Hz)
    sf = 22050;                 % sample frequency (Hz)
    d = 1.0;                    % duration (s)
    n = sf * d;                 % number of samples
    s = (1:n) / sf;             % sound data preparation
    s = sin(2 * pi * cf * s);   % sinusoidal modulation
    sound(s, sf);               % sound presentation
    pause(d + 0.5);             % waiting for sound end

end

However when I run the code, I get the following error:

??? Error using ==> sound
Too many input arguments.

Error in ==> makesound at 14
sound(Beep,rate);

What is wrong?

Upvotes: 3

Views: 2465

Answers (1)

Itamar Katz
Itamar Katz

Reputation: 9655

You probably have some function in your path, 'name hiding' a Matlab function. This function takes a smaller number of input arguments then Matlab's, therefore the Too many input arguments. In my case it was assert that caused the problem, in your case it could be anything. Walk step-by-step with the debugger (using F11 to jump into all functions you have along the way) till you find the place where some function fails. Then make sure the path where the problematic function sits, is at the bottom of Matlab's path list, so the default call is made to Matlab's function.

Upvotes: 1

Related Questions