永发信息网

matlabsimulink中使用S函数报错 Caused by: Invalid field name 'NumoutPuts'.具体函数如下

答案:2  悬赏:70  手机版
解决时间 2021-03-01 17:48
  • 提问者网友:相思似海深
  • 2021-03-01 02:25
报错Error in 'DirectMotorControlnew/Subsystem2/S-Function' while executing MATLAB S-function 'observer', flag = 0 (initialize), at start of simulation.Caused by:Invalid field name 'NumoutPuts'
function [sys,x0,str,ts,simStateCompliance]=observer(t,x,u,flag,Rs,Rr,Lr,Lm)
switch flag,
case 0
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;
case 1
sys=mdlDerivatives(t,x,u,Rs,Rr,Ls,Lr,Lm);
case 3
sys=mdlOutputs(t,x,u);
case { 2, 4, 9 }
sys=[];
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes()
sizes = simsizes;
sizes.NumContStates=4;
sizes.NumoutPuts=6;
sizes.NumlnPuts=6;
sys = simsizes(sizes);
str = [];
x0=[0;0;0.01;0.01];
ts = [-1 0]; % inherited sample time

% specify that the simState for this s-function is same as the default
simStateCompliance = 'DefaultSimState';

function sys=mdlDerivatives(t,x,u,Rs,Rr,Ls,Lr,Lm)
a=l-Lm*Lm/(Ls*Lr);
La=Ls*Lr-Lm*Lm;
c=a*Ls*Lr/Lm;
al=-Rs/(a*Ls)-Rr/(a*Lr);
g1=-(Rs/Ls+Rr/Lr)/a;
g2=-u(3);
g3=u(3);
g4=-(Rs/Ls+Rr/Lr)/a;
g5=-Rs;
g6=0;
g7=0;
g8=-Rs;
sys(l)=[g1-u(6)/(a*Ls)-Rr/(a*Lr)]*x(l)+[-u(3)+g2]*x(2)+Rr/La*x(3)+u(3)*x(4)/(a*Ls)+u(l)/(a*Ls)-g1*u(4)-g2*u(5);
sys(2)=[u(3)+g3]*x(l)+[g4-u(6)/(a*Ls)-Rr/(a*Lr)]*x(2)-u(3)*x(3)/(a*Ls)+Rr/La*x(4)+u(2)/(a*Ls)-g3*u(4)-g4*u(5);
sys(3)=(g5-u(6))*x(1)+u(l)-g5*u(4)-g6*u(5);
sys(4)=(g8-u(6))*x(2)+u(2)-g7*u(4)-g8*u(5);
function sys=mdlOutputs(t,x,u)
sys(l)=u(4)-x(l);sys(2)=u(5)-x(2);sys(3)=x(3);
sys(4)=x(4);sys(5)=u(4);sys(6)=u(5);
最佳答案
  • 五星知识达人网友:英雄的欲望
  • 2021-03-01 02:37
你这行写错了
sizes.NumoutPuts=6;

O大写
全部回答
  • 1楼网友:北城痞子
  • 2021-03-01 02:54
不明白啊 = =!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯