MATLAB: Error: not enough input arguments

not enoght

Hello everybody. When I run this program an error appears "Not enough input arguments.. in line 2". Can anyone help me?
function [avg, med] = mystats(x)
n=length(x);
avg=mymean(x,n);
med=mymedian(x,n);
end
function a=mymean(v,n)
a=sum(v)/n;
end
function m=mymedian(v,n)
w=sort(v);
if rem(n,2)==1
m=w((n+1)/2);
else
m=(w(n/2)+w(n/2+1))/2;
end
end

Best Answer

How did you call [avg, med] = mystats(x)? You didn't just hit F5 or the green run triangle to run it without supplying a value for x did you? Because that won't work. You need to assign x and then call it in a script of function like this, in a script you might call test_mystats.m:
x = rand(1, 10000); % Generate 10000 random numbers.
% Get the stats:
[avg, med] = mystats(x)
Related Question