For loop in function

조회 수: 1 (최근 30일)
Judith Lange
Judith Lange 2018년 5월 30일
편집: Judith Lange 2018년 6월 1일
I tried to create a function with a for loop inside. When I try to use this function with the function handle some errors occur (when I just type it in the command window it works). But no matter what I try the error: Not enough input arguments always stays.
function y = fun_BSB(x,c_CSB_KA,c_AFS_KA,i_CSB_oTS)
for j=1:32
y(j)=0.625*(c_CSB_KA(j)-c_AFS_KA(j)*i_CSB_oTS(j)*x(1)*(1-x(2))-c_CSB_KA(j)*x(3));
end
end
Next Script:
fun=@fun_BSB;
x0=[0.02,0.02,0.035];
weight = abs(c_BSB5_KA);
for k=1:length(c_BSB5_KA)
[x,fval] = fgoalattain(fun,x0,c_BSB5_KA(k),weight(k));
ak(k,1:3)=x;
end
I know that there are probably many other mistakes in my script but could anybody help me with the error "Not enough input arguments"?
Not enough input arguments.
Error in fun_BSB (line 4)
y(j)=0.625*(c_CSB_KA(j)-c_AFS_KA(j)*i_CSB_oTS(j)*x(1)*(1-x(2))-c_CSB_KA(j)*x(3));
...some other errors...
Caused by:
Failure in initial objective function evaluation.
Optimization cannot continue.
Thank you for your help!

채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 30일
  댓글 수: 1
Judith Lange
Judith Lange 2018년 6월 1일
편집: Judith Lange 2018년 6월 1일
Thank you very much. This link really helped me and even I understood it. Now I am going to fix the other problems :D

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by