Error regarding not enough input arguments
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Keep getting error saying not enough input arguments and can't figure out what i did wrong.
function sinusoid(sinusoid_type,attenuation_factor,frequency,phase)
if nargin==3
phase=0;
end
t=0:0.0025:2*pi;
if sinusoid_type==1
mt=exp(-attenuation_factor*t).*sin((2*pi*frequency*t)+phase);
else
mt=exp(-attenuation_factor*t).*cos((2*pi*frequency*t)+phase);
end
plot(t,mt);
hold on;
plot(t,exp(-attenuation_factor*t),'--r');
hold on;
plot(t,-exp(-attenuation_factor*t).'--r');
hold off;
end
1 comentario
Will Donny
el 1 de Dic. de 2018
Respuestas (1)
Star Strider
el 1 de Dic. de 2018
How did you call your ‘sinusoid’ function?
You must provide ‘sinmusoid_type’ and the other arguments. Your function will not pick them up from your workspace.
The most frequent reason that ‘not enough input arguments’ occurs if you have provided what appear to be the necessary number of them, is that you have a variable or script that has the same name as one of the functions that’s throwing that error. This is called ‘overshadowing’ of MATLAB functions, and is to be absolutely avoided.
I don’t know the function that threw that error, since you didn’t provide that information. If it was exp for example, run this line from a script or your Command Window:
which exp -all
If the first line is:
exp is a variable.
you’ve found your problem. The solution is to rename the variable to one that doesn’t conflict with any built-in MATLAB functions. Do that for whatever function is throwing the error.
2 comentarios
Will Donny
el 1 de Dic. de 2018
Star Strider
el 1 de Dic. de 2018
My pleasure.
You need to call your ‘sinusoid’ function as:
sinusoid_type = ...;
attenuation_factor = ...;
frequency = ...;
phase = ...;
sinusoid(sinusoid_type,attenuation_factor,frequency,phase)
The variables don¹t have to be the same names as the variables in your function, but you have to define each of them specifically as something, or you will get the errors you see.
I didn’t see ‘e’ anywhere in your code. The exp function is the correct way to invoke it.
Also, you’ll probably want ‘nargin < 4’ rather than ‘nargin == 3’ here:
if nargin < 4
phase=0;
end
La pregunta está cerrada.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!