声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4207|回复: 2

[综合讨论] 运行S函数出现 flag=2 call must be a real vector of length 0错误

[复制链接]
发表于 2009-3-25 10:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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 = [];
回复
分享到:

使用道具 举报

发表于 2009-3-26 09:30 | 显示全部楼层
把这个改改看怎么样
sizes.DirFeedthrough = 1;
因为你的方程没有状态变量,输出是由输入直接控制的。
发表于 2012-3-21 20:47 | 显示全部楼层
单独运行S函数是会报错,但是和Simulink结合仿真就没事了
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-16 06:14 , Processed in 0.066794 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表