如何循环最小?

时间:2011-12-05 20:23:41

标签: octave

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

2 个答案:

答案 0 :(得分:0)

尝试一下

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

我猜这是因为你从未用endif

关闭你的if

答案 1 :(得分:0)

为什么不摆脱语法错误加速代码:

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);