如何在用M文件编写的s函数中定义一个向量变量啊?
我用M文件编写的s函数,想定义一个向量变量用于存储数据,可是总是提示我说变量未定义,这是怎么回事啊?那位给看看,多谢了。function = para(t,x,u,flag,w,r)
W(1:1:64)=0;
r(1:1:64)=0;
mo=0.033;
switch flag,
case 0,
=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 =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= ;
str = [];
ts= ;
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 = [];
找到错误了,多谢了
找到错误了,多谢了
页:
[1]