2011-12-05 72 views
0
for i = 1:n 
     ymin = realmax; 
     ymax = 0; 
     for j = 1:4 % each perceptron 
      for k = 1:40 
       yval = waves0(k,j,i); 
       if(yval > ymax) ymax = yval; 
       if(yval < ymin) ymin = yval; 
      end 
     end 
end 

我試圖找到最小和最大值,但是當我運行的功能,我得到:如何循環分鐘?

parse error near line 20 of file /Volumes/FDISK/mlr/YvalDistance.m 

    syntax error 



parse error near line 20 of file /Volumes/FDISK/mlr/YvalDistance.m 

    syntax error 



parse error near line 20 of file /Volumes/FDISK/mlr/YvalDistance.m 

    syntax error 



parse error near line 20 of file /Volumes/FDISK/mlr/YvalDistance.m 

    syntax error 

第20行是函數的最後一行,並且是空的。 如果我評論if(yval < ymin) ymin = yval;我再也不會收到解析錯誤了。這是怎麼回事?

octave:39> version 
ans = 3.2.4 
+0

您應該關閉[if with endif](http://www.g nu.org/software/octave/doc/interpreter/The-_003ccode_003eif_003c_002fcode_003e-Statement.html#The-_003ccode_003eif_003c_002fcode_003e-Statement)但你有1k,這不是問題。 – danihp

+0

您是否試過用endfor關閉您的for循環? – 2011-12-05 20:32:46

回答

0

爲什麼不能擺脫你的語法錯誤的速度up your code with:

yvals = zeros(1,4*40); 
for j = 1:4 
    for k = 1:40 
     yvals((j*4)+k) = waves0(k,j,i); 
    end 
end 
ymax = max(yvals); 
ymin = min(yvals); 
0

嘗試一些沿

if (yval > ymax) 
    ymax = yval; 
else if (yval < ymin) 
    ymin = yval; 
endif 

我猜測它的線條是因爲你從來不關你的,如果有一個ENDIF