<P>下面是我的一个函数:<BR>function k=demoBreak(n)<BR> x=rand(1,n);<BR> k=1;<BR> while k<=n<BR> if x(k)>0.8<BR> break<BR> end<BR> k=k+1;<BR> end<BR> disp(x(k));<BR>在命令行运行时出现如下故障:<BR>>> demoBreak(1)<BR>??? Attempted to access x(2); index out of bounds because numel(x)=1.</P>
<P>Error in ==> demoBreak at 10<BR> disp(x(k));<BR>我不明白的是x明明是rand(1,n),与k的取值无关呀。而且也没有限定边界呀。<BR>还请大虾指点迷津。不胜感谢!</P>