[求助] S函数的多输入问题
<P>系统提示错误如下,系统有输入,但就是没有赋值给s函数 我改动后,现在有提示:<BR><BR>??? Undefined function or variable 'u1'.</P><P>Error in ==> C:\MATLAB6p5\work\sfun_bmfa.m (mdlOutputs)<BR>On line 50==> w=u1;</P>
<P>Error in ==> C:\MATLAB6p5\work\sfun_bmfa.m<BR>On line 19==> sys=mdlOutputs(t,x,u,k);<BR><BR><BR><BR>源程序如下:<BR><BR>function = sfun_bmfa(t,x,u,flag,k)<BR>global pos;<BR>global w;<BR>%<BR>%<BR>%<BR>switch flag,<BR>case 0,<BR> =mdlInitializeSizes;<BR>case 1,<BR> sys=mdlDerivatives(t,x,u);<BR>case 2,<BR> sys=mdlUpdate(t,x,u);<BR>case 3,<BR> sys=mdlOutputs(t,x,u,k);<BR>case 9, <BR> sys=mdlTerminate(t,x,u);<BR>otherwise<BR> error(['Unhandled flag = ',num2str(flag)]);<BR>end</P>
<P>% ------ mdlInitializeSizes ------------------------<BR>function =mdlInitializeSizes(angzzy)<BR>sizes = simsizes; <BR>sizes.NumContStates= 0;<BR>sizes.NumDiscStates= 0;<BR>sizes.NumOutputs = 1;<BR>sizes.NumInputs = 2; <BR>sizes.DirFeedthrough = 1;<BR>sizes.NumSampleTimes = 1; <BR>sys = simsizes(sizes);<BR>x0= [ ];<BR>str = [ ]; <BR>ts= ;<BR>% -----mdlDerivatives -----------------------------<BR>function sys=mdlDerivatives(t,x,u)<BR>sys =[ ] ; <BR>% -----mdlUpdate ----------------------------------<BR>function sys=mdlUpdate(t,x,u)<BR>sys = [ ]; <BR>% -----mdlOutputs ---------------------------------<BR>function sys=mdlOutputs(t,x,u,k)<BR>w=u1;<BR>pos=u2;</P>
<P>if u2<=pi/3;<BR> sys=k*u1;<BR> <BR>else if u2<=2*pi/3;<BR> sys=k*u1;<BR> </P>
<P> else if u2<=pi;<BR> sys=k*u1*((-2)*u2/(pi/3)+5);<BR> <BR> else if u2<=4*pi/3;<BR> sys=-k*u1;<BR> <BR> else if u2<=5*pi/3;<BR> sys=-k*u1;<BR> <BR> else u2<=2*pi;<BR> sys=k*u1*(u2/(-pi/6)+9);<BR> <BR> <BR> end<BR> end<BR> end<BR> end<BR>end<BR>% -----mdlTerminate -------------------------------<BR>function sys=mdlTerminate(t,x,u)<BR>sys = [ ]; <BR><BR><BR>请高手指点如何修改?<BR><BR><BR>不胜感谢.......<BR></P>
回复:(hitwrg)[求助] S函数的多输入问题
<DIV class=quote><B>以下是引用<I>hitwrg</I>在2006-3-31 11:04:48的发言:</B><BR><P><BR>function sys=mdlOutputs(t,x,u,k)<BR>w=u1;<BR>pos=u2;</P>
<P>if u2<=pi/3;<BR> sys=k*u1;<BR> <BR>else if u2<=2*pi/3;<BR> sys=k*u1;<BR> </P>
<P> else if u2<=pi;<BR> sys=k*u1*((-2)*u2/(pi/3)+5);<BR> <BR> else if u2<=4*pi/3;<BR> sys=-k*u1;<BR> <BR> else if u2<=5*pi/3;<BR> sys=-k*u1;<BR> <BR> else u2<=2*pi;<BR> sys=k*u1*(u2/(-pi/6)+9);<BR> <BR> <BR> end<BR> end<BR> end<BR> end<BR>end<BR>% -----mdlTerminate -------------------------------<BR>function sys=mdlTerminate(t,x,u)<BR>sys = [ ]; <BR><BR><BR></P></DIV>
<P>你这里的u1 u2<BR>是哪来的?</P>
用S function builder很快就能搞定!
在builder里面添加输入输出参数就ok了!我用的非常多,很方便!回复:(Jackilin)用S function builder很快就能搞定...
<BR><BR><BR><BR>已搞ding<BR>多谢大家关注<BR><BR><BR><BR>
页:
[1]