Not enough input arguments

2 views (last 30 days)
Joaquin Saldain
Joaquin Saldain on 24 Feb 2018
Commented: Walter Roberson on 26 Feb 2018
I am minimizing a function that I created. Getting "Not enough input arguments".
This is the main code:
y=data;
y0=0;
global y y0;
theta0=[0.5, 0.5];
[x,fval,exitflag,output,grad,hessian] = fminunc(condlike,theta0)
This is the function file:
function [ f ] = condlike(x )
Conditional likelihood evaluation for AR(1)
global y y0
[m,n]=size(y);
g = normpdf(y(1,1),x(1)*y0,x(2));
for i=1:n-1
g=g+log(normpdf(y(1,i+1),x(1)*y(1,i),x(2)));
end
f=-g;
end

Accepted Answer

Rik
Rik on 24 Feb 2018
You forgot to make the first input a function handle, using an @ character. The code below ran without errors for me.
data=rand(10,1);
global y y0;
y=data;
y0=0;
theta0=[0.5, 0.5];
[x,fval,exitflag,output,grad,hessian] = fminunc(@condlike,theta0);
function [ f ] = condlike(x )
%Conditional likelihood evaluation for AR(1)
global y y0
[~,n]=size(y);
g = normpdf(y(1,1),x(1)*y0,x(2));
for i=1:n-1
g=g+log(normpdf(y(1,i+1),x(1)*y(1,i),x(2)));
end
f=-g;
end
  3 Comments
Joaquin Saldain
Joaquin Saldain on 26 Feb 2018
If I needed to provide an argument to @condlike that is a parameter, so not affected by the minimization, how could I do it?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!