|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
<P>请各位兄弟姐妹帮帮手!!<BR><BR>我在用S函数时,从来没有一个程序能够通过,比如我把下面的这个程序复制到editor里面:<BR><BR>function [sys,x0,str,ts] = 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,[sys,x0,str,ts]=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 [sys,x0,str,ts]=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 = [0 0]; <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> |
|