user1135541
user1135541

Reputation: 1891

Prevent Octave from printing out the vector

I have the following script:

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, ".");

Every time it iterates through the do - until loop, it tries to print x_out and y_out to console, why? How do I prevent it from printing out the vectors every time?

Upvotes: 0

Views: 171

Answers (1)

Ander Biguri
Ander Biguri

Reputation: 35525

Because you did not supress the output. Use ; for that.

Here:

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

Upvotes: 3

Related Questions