why does it keep saying "not enough input arguments" when i run my code?

i have the following code and every time i try to run it it keeps saying not enough input arguments even though the inputs are listed in the function.
function filtered_data=moving_average_filter(new_hand_xyz, n)
for t=1:length(new_hand_xyz)
xn=t-n;
if t==1
filtered_data(1)=new_hand_xyz(1);
else
if xn<1
xn=1;
end
filtered_data(t)=filtered_data(t-1)+(1/n)*(new_hand_xyz(t)-new_hand_xyz(xn));
end
end
Can anyone help?

Respuestas (1)

The arguments listed in the function definition are simply "dummy arguments"; they're placeholders and names to be used internal to the function for the values supplied by the caller. They have no values unless given in the argument list when the function is executed/called and the names in the argument list even if the same as some variables you have assigned in the work or calling scope they're not the same variable. Only by association in the calling statement are the two ever brought together.
You must call your function with two arguments...
x=somedataseriesyourwantfiltered;
N=thefiltervalue;
y=moving_average_filter(x,N);
NB: you can do a moving average filter much faster with
coeff=ones(1,N)/N;
y=conv(x,coeff,'valid');
to keep the points only that are computed without zero-padding. See
doc conv % details other options for treating end effects

4 comentarios

function filtered_data=moving_average_filter(velocity_xyz, new_hand_xyz)
y=velocity_xyz;
data_to_filter= new_hand_xyz;
n=1;
l=length(y);
n=1;
threshold=0.015;
while n<=25
for w= 1: l-1
if (y(w)>threshold && y(w+1)<threshold) || ...
(y(w)<threshold && y(w+1)>threshold)
n=n+1;
end
end
end
for t=1:length(data_to_filter)
xn=t-n;
if t==1
filtered_data(1)=data_to_filter(1);
else
if xn<1
xn=1;
end
filtered_data(t)=filtered_data(t-1)+(1/n)*(data_to_filter(t)-data_to_filter(xn));
end
end
Thank you for your help! I've given the functions a value in the argument of the function but i'm still getting that the there's not enough input arguments at the line where the filter starts. I really don't know where i am going wrong? :/
dpb
dpb el 15 de Abr. de 2017
Editada: dpb el 16 de Abr. de 2017
But those changes are INSIDE!!! the function; have no effect whatsoever on what the values are for the arguments when the function is called.
It is the responsibility of the CALLING code to pass the arguments TO the function. You haven't shown how you're trying to use the function at all which is where the problem is, not in the function itself.
Your function is not different than any other including builtins...if try any other function at the command line...
> mx=max
Error using max
Not enough input arguments.
>>
Look familiar??? What is MAX to try to take the maximum of when nothing was passed to it?
>> mx=max(x)
mx =
1.2139e-04
>>
I suggest working thru the tutorials at
I was being silly lol! i get where i went wrong.
Thank you for your help!
Glad to try...sometimes it's hard to see forest for the trees: when things are just too obvious we often try to complicate what isn't.
How about Accept answer to if nothing else indicate thread closed???

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Abr. de 2017

Comentada:

dpb
el 28 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by