Why do I get the error message of using too many input argument when using the spectrogram function?

I am using the following code:
path2=['D:\Uni\0-SysMuWi\Masterthesis\Musikausschnitte_Hoertest2\Klavier+Gesang.wav']
[a,Fs] = audioread(path2);
W=256;
h=hanning(W);
b=[2 4 6 8];
Y=64:
spectrogram(path2,h,W/2,Y,Fs)
And I get the error message:
Error using spectrogram Too many input arguments.
Error in spectrum_numerated (line 52) spectrogram(b,hanning(W),W/2,Y,Fs)
I also used "b" instead of "path2" in the spectrogram function but I still get the same error message.

 채택된 답변

The current online documentation is for R2017a. If you have a different release (version), type
doc spectrogram
in your Command Window to display the documentation and examples for your version. Differences between versions could explain the error your code is throwing.

댓글 수: 4

Thank you for your answer. Indeed, I'm using version 2015b but when I open the documentation I get the same code and examples..
My pleasure.
If the example code throws the same error, the only other possibility is that you have somehow ‘overshadowed’ the spectrogram function with a variable, or with your own spectrogram function.
Run this line from your Command Window (or a script):
which spectrogram -all
The only result should be:
C:\Program Files\MATLAB\R2015b\toolbox\signal\signal\spectrogram.m
If you get anything else, you have found the problem. The solution in that situation is to rename your variable or function to something other than ‘spectrogram’.
THANK YOU! That was the problem. I found a second function of the MIR toolbox with the same name, I changed it and now it works.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2017년 5월 24일
편집: Jan 2017년 5월 24일
The calling sequence is:
[s,f,t] = spectrogram(x,window,noverlap,f,fs)
x is the signal. I do noth think that the file name or "b" (what ever this mean exactly) is what you want. I'd expect a to be the first input.
I'm surprised that the code works at all, because this line should fail:
Y=64:
A trailing colon? Is this a typo in the forum? If yo, please post the code exactly how you run it.

댓글 수: 3

Thank you for your answer. I want to analyze a music excerpt with the spectrogram.
Sorry, yes, it's a typo in the code here, in matlab it's
Y=64;
When I use your calling sequence and the variables from my code above, I still get the error message. So I guess it's the file name that's causes the error?
[s,Y,t] = spectrogram(a,h,W/2,Y,Fs)
No, there is no connection to the file name. Try to identify the problem by using the debugger:
dbstop if error
Now run the code again until it stops. Look in the editor and search in the surrounding lines. The function spectrogram is called with 5 inputs, which is actually allowed. But perhaps you call it with unexpected arguments? Try to run the code examples from the documentation then. Do they run? Then examine, what is the difference to you way to call it.
If I add the debugger into the code, I jusst get the same error message.
The examples don't run either. I tried three example by copying and pasting:
N = 1024;
n = 0:N-1;
w0 = 2*pi/5;
x = sin(w0*n)+10*sin(2*w0*n);
s = spectrogram(x);
spectrogram(x,'yaxis')
Error: Error using / Matrix dimensions must agree.
Error in spectrogram (line 25) nsegs = floor(s/(segsize/nlap))-nlap+1;
Error in test_example (line 9) spectrogram(x,'yaxis')
>> t = 0:0.001:2;
x = chirp(t,100,1,200,'quadratic');
>> spectrogram(x,128,120,128,1e3)
Error using spectrogram Too many input arguments.
>> Fs = 1000;
t = 0:1/Fs:2-1/Fs;
y = chirp(t,100,1,200,'quadratic');
>> spectrogram(y,100,80,100,Fs,'yaxis')
view(-77,72)
shading interp
colorbar off
Error using spectrogram Too many input arguments.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

질문:

2017년 5월 24일

댓글:

2017년 5월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by