毕业设计求救 关于“S函数“的调试问题!!
<P>请各位兄弟姐妹帮帮手!!<BR><BR>我在用S函数时,从来没有一个程序能够通过,比如我把下面的这个程序复制到editor里面:<BR><BR>function = csfunc(t,x,u,flag) <BR>%CSFUNC An example M-file S-function for defining a continuous system. <BR>% Example M-file S-function implementing continuous equations: <BR>% x' = Ax + Bu <BR>% y = Cx + Du <BR>% <BR>% See sfuntmpl.m for a general S-function template. <BR>% <BR>% See also SFUNTMPL. <BR> <BR>% Copyright (c) 1990-1998 by The MathWorks, Inc. All Rights Reserved. <BR>% $Revision: 1.5 $ <BR>A=[-0.09 -0.01; 1 0]; <BR>B=[ 1 -7; 0 -2]; <BR>C=[ 0 2; 1 -5]; <BR>D=[-3 0; 1 0]; <BR>switch flag, <BR>%%%%%%%%%%%%%%%%%% <BR>% Initialization % <BR>%%%%%%%%%%%%%%%%%% <BR>case 0,=mdlInitializeSizes(A,B,C,D); <BR>%%%%%%%%%%%%%%% <BR>% Derivatives % <BR>%%%%%%%%%%%%%%% <BR>case 1,sys=mdlDerivatives(t,x,u,A,B,C,D); <BR>%%%%%%%%%%% <BR>% Outputs % <BR>%%%%%%%%%%% <BR>case 3,sys=mdlOutputs(t,x,u,A,B,C,D); <BR>%%%%%%%%%%%%%%%%%%% <BR>% Unhandled flags % <BR>%%%%%%%%%%%%%%%%%%% <BR>case { 2, 4, 9 },sys = []; <BR>%%%%%%%%%%%%%%%%%%%% <BR>% Unexpected flags % <BR>%%%%%%%%%%%%%%%%%%%% <BR>otherwise, error(['Unhandled flag = ',num2str(flag)]); <BR>end <BR>% end csfunc <BR>% <BR>%============================================================================= <BR>% mdlInitializeSizes <BR>% Return the sizes, initial conditions, and sample times for the S-function. <BR>%============================================================================= <BR>% <BR>function =mdlInitializeSizes(A,B,C,D) <BR>sizes = simsizes; <BR>sizes.NumContStates = 2; sizes.NumDiscStates = 0; sizes.NumOutputs = 2; <BR>sizes.NumInputs = 2; sizes.DirFeedthrough = 1; sizes.NumSampleTimes = 1; <BR>sys = simsizes(sizes); x0 = zeros(2,1); str = []; ts = ; <BR>% end mdlInitializeSizes <BR>% <BR>%============================================================================= <BR>% mdlDerivatives <BR>% Return the derivatives for the continuous states. <BR>%============================================================================= <BR>% <BR>function sys=mdlDerivatives(t,x,u,A,B,C,D) <BR>sys = A*x + B*u; % end mdlDerivatives <BR>% <BR>%============================================================================= <BR>% mdlOutputs <BR>% Return the block outputs. <BR>%============================================================================= <BR>% <BR>function sys=mdlOutputs(t,x,u,A,B,C,D) <BR>sys = C*x + D*u; % end mdlOutputs <BR><BR><BR>接着在command windows里面总会出现下面的情况:<BR><BR>??? Input argument "flag" is undefined.</P><P>Error in ==> csfunc at 17<BR>switch flag, <BR><BR>我用Matlab里面的关于S函数的.m文件也会出现这样的问题,请问是怎么回事呢?谢谢各位给点指点吧!</P>
毕业设计求救 关于“S函数“的调试问题!
你的程序没有问题,S-Function 是为了解决复杂问题给用户提供的用函数形式解决用simulink搭建复杂或难以实现的问题<BR>它的用法和内在模块用法基本上一样,函数名需要放在mdl S-Function模块的参数中<BR>希望各位多多发言回复:(cyberdstar)毕业设计求救 关于“S函数“的调...
<P>那它为什么在editor里面run的时候会出现<BR><BR>??? Input argument "flag" is undefined.</P><P>Error in ==> pid at 6<BR>switch flag<BR><BR>这是什么问题呢?<BR><BR>这样的话,我就不知道我写的程序对与错啊,是否合格?</P>
回复:(superfyue)回复:(cyberdstar)毕业设计求救...
<DIV class=quote><B>以下是引用<I>superfyue</I>在2006-5-19 16:27:46的发言:</B><br><P>那它为什么在editor里面run的时候会出现<br><br>??? Input argument "flag" is undefined.</P>
<P>Error in ==> pid at 6<br>switch flag<br><br>这是什么问题呢?<br><br>这样的话,我就不知道我写的程序对与错啊,是否合格?</P></DIV>
<P>
<P>这个问题要高人能回答<br><br>我只知道这么多了<br>mdl文件也可调试<br>你把你的函数加进去调试就ok了<br>你那样运行,第一遇到的未定义是flag,实际上你t,x,u等都是没定义的<br>同样你写一个带输入数参数函数那样运行也会出错的<br></P>
[此贴子已经被作者于2006-5-19 16:39:11编辑过]
S函数是作为一个模块运行的,如果直接运行s函数的话肯定会报错的,不信可以试一下 我理解的s函数的用法是这样的:可以用editor模块来编,然后将他放在mdl中作为一个模块,当然其中的函数名设置必须对应,然后加入你的输入输出信号,才能调试。
单独,是不能调试滴:) 楼上说的对
还要放在同一目录下 我也是阿,在simulink中应用编写的S函数M文件,报错
flag = 3 (output), at time 0. MATLAB error message:
Input argument "flag" is undefined
是怎么回事啊?愿那位大虾指点一下阿! 原帖由 abcd2562 于 2007-10-17 12:02 发表 http://www.chinavib.com/forum/images/common/back.gif
我也是阿,在simulink中应用编写的S函数M文件,报错
flag = 3 (output), at time 0. MATLAB error message:
Input argument "flag" is undefined
是怎么回事啊?愿那位大虾指点一下阿!
flag未定义,是很常见的语法错误呀
哦哦
你的函数名称或参数名称定义与系统规定的东西名称冲突。改一下函数或参数的名称。 程序的文件名定义也不能与系统的内部标记名相同,不然也会出错,比如,你不能定义‘ double’为函数名或文件名.
页:
[1]