How to fix this error : Not enough input arguments.

Hi Everyone, i am an Egnineering student new to MATLAB Coding and working on Coding arithmetic optimization Algorathim (AOA).
I keep Having this Erorr : Not enough input arguments.
Error in AOA_new6 (line 5)
Best_P=zeros(1,Dim);
i am trying to modifi the code for global optimization.
i added the code for refrence.
it's not my work.
function [Best_FF,Best_P,Conv_curve]=AOA_new6(N,M_Iter,LB,UB,Dim,fhd,Function_ID,Global_Opt)
disp('AOA Working');
%Two variables to keep the positions and the fitness value of the best-obtained solution
Best_P=zeros(1,Dim);
Best_FF=inf;
Conv_curve=zeros(1,M_Iter);
%Initialize the positions of solution
X=initialization(N,Dim,UB,LB);
Xnew=X;
Ffun=zeros(1,size(X,1));% (fitness values)
Ffun_new=zeros(1,size(Xnew,1));% (fitness values)
MOP_Max=1;
MOP_Min=0.2;
C_Iter=1;
Alpha=5;
Mu=0.499;
for i=1:size(X,1)
%Ffun(1,i)=F_obj(X(i,:)); %Calculate the fitness values of solutions
Ffun(1,i)=feval(fhd,X(i,:)',Function_ID); %Calculate the fitness values of solutions
if Ffun(1,i)<Best_FF
Best_FF=Ffun(1,i);
Best_P=X(i,:);
end
end
while C_Iter<M_Iter+1 %Main loop
MOP=1-((C_Iter)^(1/Alpha)/(M_Iter)^(1/Alpha)); % Probability Ratio
MOA=MOP_Min+C_Iter*((MOP_Max-MOP_Min)/M_Iter); %Accelerated function
%Update the Position of solutions
for i=1:size(X,1) % if each of the UB and LB has a just value
for j=1:size(X,2)
r1=rand();
if (size(LB,2)==1)
if r1<MOA
r2=rand();
if r2>0.5
Xnew(i,j)=Best_P(1,j)/(MOP+eps)*((UB-LB)*Mu+LB);
else
Xnew(i,j)=Best_P(1,j)*MOP*((UB-LB)*Mu+LB);
end
else
r3=rand();
if r3>0.5
Xnew(i,j)=Best_P(1,j)-MOP*((UB-LB)*Mu+LB);
else
Xnew(i,j)=Best_P(1,j)+MOP*((UB-LB)*Mu+LB);
end
end
end
if (size(LB,2)~=1) % if each of the UB and LB has more than one value
r1=rand();
if r1<MOA
r2=rand();
if r2>0.5
Xnew(i,j)=Best_P(1,j)/(MOP+eps)*((UB(j)-LB(j))*Mu+LB(j));
else
Xnew(i,j)=Best_P(1,j)*MOP*((UB(j)-LB(j))*Mu+LB(j));
end
else
r3=rand();
if r3>0.5
Xnew(i,j)=Best_P(1,j)-MOP*((UB(j)-LB(j))*Mu+LB(j));
else
Xnew(i,j)=Best_P(1,j)+MOP*((UB(j)-LB(j))*Mu+LB(j));
end
end
end
end
Flag_UB=Xnew(i,:)>UB; % check if they exceed (up) the boundaries
Flag_LB=Xnew(i,:)<LB; % check if they exceed (down) the boundaries
Xnew(i,:)=(Xnew(i,:).*(~(Flag_UB+Flag_LB)))+UB.*Flag_UB+LB.*Flag_LB;
%Ffun_new(1,i)=F_obj(Xnew(i,:)); % calculate Fitness function
Ffun_new(1,i)=feval(fhd,Xnew(i,:)',Function_ID); %Calculate the fitness values of solutions
if Ffun_new(1,i)<Ffun(1,i)
X(i,:)=Xnew(i,:);
Ffun(1,i)=Ffun_new(1,i);
end
if Ffun(1,i)<Best_FF
Best_FF=Ffun(1,i);
Best_P=X(i,:);
end
end
%Update the convergence curve
Conv_curve(C_Iter)=Best_FF-Global_Opt;
%Print the best solution details after every 50 iterations
if mod(C_Iter,50)==0
display(['At iteration ', num2str(C_Iter), ' the best solution fitness is ', num2str(Best_FF-Global_Opt)]);
end
C_Iter=C_Iter+1; % incremental iteration
end

1 comentario

Should i define the variables : N,M_Iter,LB,UB,Dim,fhd,Function_ID,Global_Opt ?

Iniciar sesión para comentar.

Respuestas (1)

Hello
Most probably you are not calling the function with all the necessary input parameters, look at this example in which there are 3 parameters required and I only pass 2.
test(2,3)
Not enough input arguments.

Error in solution>test (line 3)
out = a*b*c;
function out = test(a,b,c)
out = a*b*c;
end

8 comentarios

so i am calling less arguments that nedded ?
yes, most probably. Just to test try something like
[Best_FF,Best_P,Conv_curve]=AOA_new6(1,2,3,4,5,6,7,8)
The answer will be wrong and there may be other errors but not enough input arguments should disappear.
Now i get this error : >> AOA_new6(1,2,3,4,5,6)
File: AOA_new6.m Line: 1 Column: 47
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
syntax error. To construct matrices, use brackets instead of parentheses.
this solved the not enough arguments but how would i implement this modification to my code ?
Sorry my English is not the best.
Of course, that was just to pass enough arguments, but 1,2,3,4,5,6 is not the same as N,M_Iter,LB,UB,Dim,fhd,Function_ID,Global_Opt
Abdulaziz Hassoun
Abdulaziz Hassoun el 7 de Mzo. de 2023
Editada: Abdulaziz Hassoun el 7 de Mzo. de 2023
do i need to defineeach one of these (N,M_Iter,LB,UB,Dim,fhd,Function_ID,Global_Opt) ?
like N=5; and so on or this is the function calleing job ?
the code now runs but without output ???
We assume you got it working because you accepted this answer. It that's not true, then unaccept it and maybe more people will answer.
Oh ok i did not know that, Thank you

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2022b

Preguntada:

el 7 de Mzo. de 2023

Comentada:

el 21 de Mzo. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by