Not enough input arguments

1 Ansicht (letzte 30 Tage)
Joaquin Saldain
Joaquin Saldain am 24 Feb. 2018
Kommentiert: Walter Roberson am 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

Akzeptierte Antwort

Rik
Rik am 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 Kommentare
Joaquin Saldain
Joaquin Saldain am 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by