ali meghdadi
ali meghdadi

Reputation: 15

Too many input arguments" error in genetic algorithm

I want to minimize a very simple function.

function z=f(x)
    f=(x(1)-2)^2+(x(2)-1)^2
end

and I write this in matlab command window:

>> [x fval]=ga(@f,2)

But I get this error:

??? Error using ==> ga

Too many input arguments.

Any suggestions to fix this problem?

Upvotes: 0

Views: 1011

Answers (1)

Daniel
Daniel

Reputation: 36710

If you have multiple ga.m, the build in and your own ga.m in C:\Users\student\Documents\MATLAB\ga.m, matlab uses

  1. Files in the current directory
  2. Files in the order they are placed on path

Obviously, your ga.m is first in order, which causes Matlab to call it instead of the buildin. Either fix the path settings, or delete C:\Users\student\Documents\MATLAB\ga.m

Upvotes: 2

Related Questions