|
楼主 |
发表于 2007-5-21 00:20
|
显示全部楼层
附件里的S-Function模块的S-Function Parameters设置为k,然后在matlab的命令窗口输入k=0;文件system1.m如下所示:(现在遇到的问题是当将k设定为其他值时,如1,2等,仿真就出现如下提示:Output returned by S-function 'system1' in 'time1/S-Function' during flag=3 call must be a real vector of length 1。如何解决?还有,可以在system1.m里面改变工作空间里面的k的值么?)
function [sys,x0,str,ts] = system1(t,x,u,flag,k)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(u,k);
case 3,
sys=mdlOutputs(x);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 1;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0];
str = [];
ts = [0 0];
function sys=mdlDerivatives(u,k)
if u==0
sys=k+1;
else sys=k;
end
function sys=mdlOutputs(x)
sys=(-1)^x; |
|