防止 Octave 打印出矢量

Prevent Octave from printing out the vector

我有以下脚本:

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 到控制台,为什么?如何防止它每次都打印出矢量?

因为你没有抑制输出。为此使用 ;

这里:

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