Hi I want to use this function :
function f = GA_fitnessfcn(x)
Kp = x(1);
Rp = x(2);
T2 = x(3);
T3 = x(4);
T4 = x(5);
T5 = x(6);
H2 = x(7);
%%%Run Simulation
simoption = simset('Solver','ode23tb','SrcWorkspace','Current');
sim('power_thermal_ga.mdl',[0 0.25],simoption);
f = H(end);
But I get this error :
Error using GA_fitnessfcn (line 3)
Not enough input arguments.
how can i fix it?

댓글 수: 8

Adam
Adam 2017년 7월 20일
How are you calling it?
Stephen23
Stephen23 2017년 7월 20일
@amid: please show us the complete error message. This means all of the red text.
Jan
Jan 2017년 7월 20일
Which one is the "line 3"?
Do you use this function like:
YourMainFunction(GA_fitnessfcn, ...)
instead of
YourMainFunction(@GA_fitnessfcn, ...)
?
amid
amid 2017년 7월 20일
this is the complete error messsage when i use the function in another mfile:
Error using gaoptimset>checkValidStrings (line 432)
Undefined function 'stringSet' for input arguments of type 'cell'.
Error in gaoptimset>checkfield (line 419)
checkValidStrings(field,value,validValues);
Error in gaoptimset (line 279)
options.(Names{j,:}) = checkfield(Names{j,:},val);
Error in ga (line 316)
options = gaoptimset(defaultopt,options);
Error in GA_Param_Identify (line 30)
[x,fval,exitflag,output,population,scores] =
ga(@GA_fitnessfcn,N_param,[],[],[],[],lb,ub,[],options);
and the massage when i run the function's mfile is :
Error using GA_fitnessfcn (line 2)
Not enough input arguments.
Adam
Adam 2017년 7월 20일
Again, how do you call the function?
Jan
Jan 2017년 7월 20일
What does "when i run the function's mfile" exactly mean? Do you hit the green arrow in the editor? Then no input arguments are defined and the message is expected. But there is no reason to start GA_fitnessfcn directly.
amid
amid 2017년 7월 20일
i call the function like this:
[x,fval,exitflag,output,population,scores] =
ga(@GA_fitnessfcn,N_param,[],[],[],[],lb,ub,[],options);
Walter Roberson
Walter Roberson 2017년 7월 21일
Please show how you constructed options

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2017년 7월 20일

0 개 추천

You can use the debugger to examine the problem by your own. Type this in the command window:
dbstop if error
Now start the code again. When it stops go up in the stack until the function gaoptimset and display the current values of
Names{j,:}
val
One of them is a cell string. So find out, why a cell string is provided here.
Please read the documentation about the debugger, because this (the debugger as well as the documentation) is the programmer's best friend.

카테고리

도움말 센터 및 File Exchange에서 Search Path에 대해 자세히 알아보기

질문:

2017년 7월 20일

댓글:

2017년 7월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by