马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我用M文件编写的s函数,想定义一个向量变量用于存储数据,可是总是提示我说变量未定义,这是怎么回事啊?那位给看看,多谢了。
function [sys,x0,str,ts] = para(t,x,u,flag,w,r)
W(1:1:64)=0;
r(1:1:64)=0;
mo=0.033;
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 2;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0 0 ];
str = [];
ts = [0.001 0];
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u,w,r)
sys(1) = u(1)-u(2);
sys(2)=x(2)+2*0.033*sys(1)*u(1);
for i=1:1:64
r(i)=r(i+1);
r(i+1)=u(1);
w(i)=w(i+1);
w(i+1)=sys(2);
end
function sys=mdlOutputs(t,x,u,w,r)
sys(1)=u(1);
sys(2)=u(1)-u(2);
sys(3)=u(1)*x(1);
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 = []; |