How to solve this ERROR: Output argument "psi" (and maybe others) not assigned during call to "...".

조회 수: 1 (최근 30일)
Hello,
I'm using a simulink model with a Matlab FCN block and have this persistent ERROR:
*Output argument "psi" (and maybe others) not assigned during call to "blocoControlador2".*
I've already read about this error and still can't understand why continues.
The code:
function [psi] = blocoControlador2( il_in,il_k,psi_in,psi_k )
a= 7.3421E-6;
b= 6.2343;
c= 457.8311;
d= 25.1627;
Icc= 10;
Isat= 694;
N= 350;
%psi=0; % !?!?!?!?
%state=0;
Af=(Isat/N)/(cos((pi/2)*((Isat/N)/Icc)));
Bf=(pi/2)*(1/Icc);
f= Af*cos(Bf*il_in);
caract= a*N*il_in + (b*N*il_in)./(c+d*N*abs(il_in));
lambAsc= a*N*(il_in-f) + (b*N*(il_in-f))./(c+d.*N*abs(il_in-f));
lambDesc = a*N*(il_in+f) + (b*N*(il_in+f))./(c+d*N*abs(il_in+f));
if il_in>il_k && il_in<=(Isat/N)&& psi_in==0
psi=0;
state=0;
end
if il_in>il_k && il_in>(Isat/N) && psi_in< lambAsc && state==0
psi= psi_k;
end
if il_in>il_k && il_in>(Isat/N) && psi_in>=lambAsc
psi=lambAsc;
state=1;
end
end
Basically, I want to initialize "psi" just inside the IF.
If I initialize the variable on the firsts lines (psi=0;) the error disappears but my test conditions will fail.
Is there any way to initialize this variable with a value just for the first time? Like an "initial condition". Because I need to declare "state" inside the IF's too. Same situation.
Thanks in advance!

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 1일
편집: Azzi Abdelmalek 2014년 4월 6일
When all the conditions don't match, the variable psi is empty, maybe you should initialize your variable psi to what is needed
  댓글 수: 1
F
F 2014년 4월 5일
Thanks!!
I add an "else" statement for when all the conditions don't match and it worked.
if... elseif.. elseif... else..

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by