why do I get the error "Not enough input arguments."

my codes are attached. please run the main.m.
the command window error is as belows:
Not enough input arguments.
Error in Get_Functions_details>objective (line 40)
selected=selected(end-K+1:end);
Error in GWO (line 50)
fitness=fobj(Positions(i,:));
Error in main (line 61)
[Best_score,Best_pos,GWO_cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);

Answers (1)

I'm not sure what all this code is doing, but the file Get_Functions_details.m, you have the local function objective():
function z=objective(x,miu,sigma,K)
x1=x(1:125);
[~,selected]=sort(x1);
selected=selected(end-K+1:end); % error will occur here
% other stuff
end
The error appears to occur at this line because it is the first line to reference any of the variables other than x. This is important because objective() is only receiving one parameter. So K, miu, sigma aren't defined in this scope.
Line 58-61 of main.m tell us that GWO() receives the function handle for objective().
% Load details of the selected benchmark function
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
[Best_score,Best_pos,GWO_cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
Line 50 of GWO() indeed appears to be calling it with a single argument.
% Calculate objective function for each search agent
fitness=fobj(Positions(i,:));

Asked:

on 23 Mar 2021

Answered:

DGM
on 24 Mar 2021

Community Treasure Hunt

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

Start Hunting!