马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
运行下面这个S函数,出现这种错误:
Discrete state(s) returned by S-function 'dtc' in 'untitled1/S-Function' during flag=2 call must be a real vector of length 0
以前见过是在FLAG=3的时候出现,这种情况到没遇到过,麻烦高手给看看。
function [sys,x0,str,ts] = dtcfunc1(t,x,u,flag)
switch flag==3,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
case {1,2,4,9},
sys=[];
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [0.001 0];
function sys=mdlOutputs(t,x,u)
u=round(u);
switch u
case 1;
sys(1)=0;sys(2)=1;sys(3)=1;
case 2;
sys(1)=0;sys(2)=0;sys(3)=1;
case 3;
sys(1)=1;sys(2)=0;sys(3)=1;
case 4;
sys(1)=1;sys(2)=0;sys(3)=0;
case 5;
sys(1)=1;sys(2)=1;sys(3)=0;
case 6;
sys(1)=0;sys(2)=1;sys(3)=0;
case 0;
sys(1)=0;sys(2)=0;sys(3)=0;
otherwise
sys(1)=0;sys(2)=0;sys(3)=0;
end
%
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 = []; |