Strange Problem - variable is filled with strange values.
显示 更早的评论
Hello,
I'm using a simulink model with a Matlab FCN block which receives for input 2 signals from his own output. Basically this:

The code from matlab function:
function [out] = blocoControlador2( il_in,il_k,psi_in,psi_k,state)
%Parameters:
a= 7.3421E-6;
b= 6.2343;
c= 457.8311;
d= 25.1627;
Icc= 10;
Isat= 694;
N= 350;
Af=(Isat/N)/(cos((pi/2)*((Isat/N)/Icc)));
Bf=(pi/2)*(1/Icc);
f= Af*cos(Bf*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));
%=====================================================================
%****************CORRENTE CRESCENTE*****************
if il_in>=il_k && psi_in>=psi_k && il_in<=(Isat/N)&& psi_in==0
psi=0;
st=0;
%psi= psi_k;
out= [ psi ; st] ;
elseif il_in>il_k && psi_in>psi_k && il_in<(Isat/N) && state==0
psi=psi_k;
st=0;
out= [ psi ; st] ;
elseif il_in>il_k && psi_in>psi_k && il_in~=(Isat/N) && state==0
psi=psi_k;
st=1; % HERE!!
out= [ psi ; st] ;
elseif il_in>il_k && psi_in>psi_k && il_in>(Isat/N) && state==1
elseif ...
elseif ...
elseif ...
...
else
disp('==========default==========')
disp(il_k)
disp(il_in)
disp(psi_k)
disp(psi_in)
disp(state)
psi=psi_k;
st=state;
out= [ psi ; st];
end
end
The strange behaviour starts in the 3rd IF.
'st' variable and 'out' vector gets the right value but the function don't send outputs correctly for the next iteration.
Instead, is given strange values to input 'state' (that should be the same as 'st').
I've already did several debugging tests and really don't understandt why this is happenning.
Can anybody help, please?!?!?
Thanks in advance!
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Configure and View Diagnostics 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!