请教各位关于M文件循环问题.
<P >请教各位大侠: <BR>当调用MATLAB FCN程序时,给MATLAB FCN编程如下:<BR><BR><v:shapetype><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path connecttype="rect" gradientshapeok="t" extrusionok="f"></v:path><lock aspectratio="t" v:ext="edit"></lock></v:shapetype></P><P ><FONT face="Times New Roman">MATLAB FCN</FONT>程序如下:</P>
<P ><FONT face="Times New Roman">function outf1=para4(yp)</FONT></P>
<P ><FONT face="Times New Roman">global y1 y2 u </FONT></P>
<P ><FONT face="Times New Roman">y1=1;yp=1</FONT></P>
<P ><FONT face="Times New Roman">y2=y1^2+2</FONT></P>
<P ><FONT face="Times New Roman">u=y2-10</FONT></P>
<P ><FONT face="Times New Roman">y1=y2</FONT></P>
<P ><FONT face="Times New Roman">yp1=yp</FONT></P>
<P ><FONT face="Times New Roman">outf1=u</FONT></P>
<P >当模块运行时,第一次调用它时赋予初值y1=1,第二次调用它时y1的初值变为y1=y2=1^2+2=3,第三次为11,.............<BR>请问各位朋友应该怎么编程实现或用模块来实现这种功能.<BR>谢谢各位的宝贵意见!!!THANK YOU!!!<BR></P>
回复:(danychen)请教各位关于M文件循环问题.
你这个程序整个逻辑就对不上<br>第一次运行时y2等于多少?[此贴子已经被作者于2006-5-13 14:59:15编辑过]
谢谢留言!!!
第一次运行时,y2=3,同时y1=y2=3,希望在下次调用时y1=3,请问应该如何编程?谢谢<BR>为表达清楚,我再把程序写一下:<BR><FONT face="Times New Roman">第一次调用para4时<BR>function outf1=para4(yp)<BR></FONT><FONT face="Times New Roman">global y1 y2 u <BR></FONT><FONT face="Times New Roman">y1=1<BR></FONT><FONT face="Times New Roman">y2=y1^2+2<BR></FONT><FONT face="Times New Roman">u=y2-10<BR></FONT><FONT face="Times New Roman">y1=y2<BR></FONT><FONT face="Times New Roman">yp1=yp<BR></FONT><FONT face="Times New Roman">outf1=u<BR>%y1=1<BR>希望第二次调用para4时,程序变为:<BR>function outf1=para4(yp)<BR><FONT face="Times New Roman">global y1 y2 u <BR></FONT><FONT face="Times New Roman">y1=3<BR></FONT><FONT face="Times New Roman">y2=y1^2+2<BR></FONT><FONT face="Times New Roman">u=y2-10<BR></FONT><FONT face="Times New Roman">y1=y2<BR></FONT><FONT face="Times New Roman">yp1=yp<BR></FONT><FONT face="Times New Roman">outf1=u<BR>从而达到循环调用的目的。<BR>请问能否用程序实现,或者可否改动模块实现???<BR>模块图为:M文件两头接个被控对象,一端为输出u,一端为输入yp<BR>THANK YOU VERY MUCH!!!<BR></FONT></FONT>
页:
[1]