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

1 view (last 30 days)
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!

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 1 Apr 2014
Edited: Azzi Abdelmalek on 6 Apr 2014
When all the conditions don't match, the variable psi is empty, maybe you should initialize your variable psi to what is needed
  1 Comment
F
F on 5 Apr 2014
Thanks!!
I add an "else" statement for when all the conditions don't match and it worked.
if... elseif.. elseif... else..

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!