防止Octave打印出矢量

时间:2017-02-28 18:35:40

标签: octave

我有以下脚本:

x = 0:1/32:10;   # 10 sec
y = floor(sin(x) * 800 + 800);

function [x_out, y_out] = compress (x_in, y_in)
    x_out = x_in;
    y_out = y_in;
    tol = 5;

    do
        dropped = false;
        idx = 1;
        while (y_out(idx + 2))
            if (x_out(idx + 1) - x_out(idx) == x_out(idx + 2) - x_out(idx + 1))
                min = y_out(idx) + y_out(idx + 2) - (2 * tol);
                max = y_out(idx) + y_out(idx + 2) + (2 * tol);
                if ((min <= y_out(idx + 1) * 2) && (y_out(idx + 1) * 2 <= max))
                    x_out(idx + 1) = []  # Drop the val
                    y_out(idx + 1) = []  # Drop the val
                    dropped = true;
                else
                    idx++;
                endif
            else
                idx++;
            endif
        endwhile
    until (dropped == false)
endfunction

[x_o, y_o] = compress (x, y);

plot(x_o, y_o, ".");

每次循环遍历do - until循环时,它会尝试将x_out和y_out打印到控制台,为什么?如何防止它每次都打印出矢量?

1 个答案:

答案 0 :(得分:3)

因为你没有压制输出。请使用;

下面:

x_out(idx + 1) = [];  # Drop the val
y_out(idx + 1) = [];  # Drop the val