MATLAB: Gamultiobj – Not enough input arguments

gamultiobj

I am trying to run gamultiobj for one objective (later, I will add more objectives) but I am getting an error 'Not enough input arguments' (fitness and gamultiobj functions are attached). I would appreciate if you have a look at the code attached. Thanks.
The detailed error:
Not enough input arguments.
Error in myfitnessfunction (line 114)
SOC(i,j)=SOC_n(i)+((cop(i)*E_max(i)*x(i)*T_s/E_cap(i)))*F(i,j)+((E_max(i)*y(i)*T_s/(cop(i)*E_cap(i))))*H(i,j);
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in gamultiobjMakeState (line 28)
Score = FitnessFcn(state.Population(1,:));
Error in gamultiobjsolve (line 8)
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);
Error in gamultiobj (line 276)
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
Error in mymainfunction (line 8)
[x,y,fval,exitflag]=gamultiobj(FitnessFunction,nvars,[],[],[],[],Lb,Ub);
Caused by:
Failure in initial fitness function evaluation. GAMULTIOBJ cannot continue.

Best Answer

olga_vm - the signature for your fitness function is
function z=myfitnessfunction(x,y)
with two inputs, x and y. The error message is telling you that there are not enough input parameters being provided to your fitness function. This makes sense since the genetic algorithm code will only pass in a single parameter or array with (in your case two elements). You will need to change your signature and first couple of lines to
function z = myfitnessfunction(data)
x = data(1);
y = data(2);