运行s-function Output argument "sys" (and possibly others) not assigned a value in the execution with "ctrl>mdlOutputs" function.
8 views (last 30 days)
Show older comments
function [sys,x0,str,ts,simStateCompliance] = ctrl(t,x,u,flag,pa)
switch flag,
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,pa);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0 0];
simStateCompliance = 'UnknownSimState';
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u,pa)
%X1 hatd x2 wm x3 wmref
r7=pa.r7;
Pn = pa.Pn;
Phi = pa.Phi;
J = pa.J;
B = pa.B;
T=pa.T;
Ts=pa.Ts;
if t<=Ts
n =T/(T-t);
n1=T - t;% n/diff(n)
else
n=T*(1+a*(T-Ts))/a/(T-Ts)/(T-Ts)-T/a/(T-Ts)/(T-Ts)*exp(-a*(t-Ts));
n1= - (exp((-a*(Ts - t)))*(exp(a*(Ts - t)) - T*a + Ts*a - 1))/a;
end
hatd=u(1);
hatwm=u(2);
wmref=u(3);
www=2*J/Phi/Pn/3*(0-hatd/Pn+B/J*hatwm+n1*(wmref-hatwm)+r7*n^(0.5)*(abs(wmref-hatwm))^0.5*sign(wmref-hatwm));
sym=www;
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];function [sys,x0,str,ts,simStateCompliance] = ctrl(t,x,u,flag,pa)
switch flag,
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,pa);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0 0];
simStateCompliance = 'UnknownSimState';
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u,pa)
%X1 hatd x2 wm x3 wmref
r7=pa.r7;
Pn = pa.Pn;
Phi = pa.Phi;
J = pa.J;
B = pa.B;
T=pa.T;
Ts=pa.Ts;
if t<=Ts
n =T/(T-t);
n1=T - t;% n/diff(n)
else
n=T*(1+a*(T-Ts))/a/(T-Ts)/(T-Ts)-T/a/(T-Ts)/(T-Ts)*exp(-a*(t-Ts));
n1= - (exp((-a*(Ts - t)))*(exp(a*(Ts - t)) - T*a + Ts*a - 1))/a;
end
hatd=u(1);
hatwm=u(2);
wmref=u(3);
www=2*J/Phi/Pn/3*(0-hatd/Pn+B/J*hatwm+n1*(wmref-hatwm)+r7*n^(0.5)*(abs(wmref-hatwm))^0.5*sign(wmref-hatwm));
sym=www;
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
0 Comments
Accepted Answer
Fangjun Jiang
on 21 Oct 2024
Edited: Fangjun Jiang
on 22 Oct 2024
Probably a typo at the last line of this code below. Should be 'sys', not 'sym'. Also need to add a line 'end' to finish this function. Do the same for other functions too.
function sys=mdlOutputs(t,x,u,pa)
%X1 hatd x2 wm x3 wmref
r7=pa.r7;
Pn = pa.Pn;
Phi = pa.Phi;
J = pa.J;
B = pa.B;
T=pa.T;
Ts=pa.Ts;
if t<=Ts
n =T/(T-t);
n1=T - t;% n/diff(n)
else
n=T*(1+a*(T-Ts))/a/(T-Ts)/(T-Ts)-T/a/(T-Ts)/(T-Ts)*exp(-a*(t-Ts));
n1= - (exp((-a*(Ts - t)))*(exp(a*(Ts - t)) - T*a + Ts*a - 1))/a;
end
hatd=u(1);
hatwm=u(2);
wmref=u(3);
www=2*J/Phi/Pn/3*(0-hatd/Pn+B/J*hatwm+n1*(wmref-hatwm)+r7*n^(0.5)*(abs(wmref-hatwm))^0.5*sign(wmref-hatwm));
sym=www;
More Answers (0)
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!