icehawk
icehawk

Reputation: 1235

suppressing printing every assignment

I have written a simple script in Octave. When I run it from the command line, Octave prints a line every time a variable gets assigned a new value. How do I suppress that?

MWE:

function result = stuff()
    result = 0
    for i=0:10,
        j += i
    end
end

when I run it:

octave:17> stuff()
result = 0
result = 0
result =  1
result =  3
result =  6
result =  10
result =  15
result =  21
result =  28
result =  36
result =  45
result =  55
ans =  55
octave:18> 

I want to get rid of the result = ... lines. I am new to Octave, so please forgive me asking such a basic question.

Upvotes: 45

Views: 17090

Answers (2)

DJanssens
DJanssens

Reputation: 20729

by adding a semicolon at the end of your statement it will suppress the intermediate result.

In your case:

function result = stuff()
    result = 0;
    for i=0:10,
        j += i;
    end
end

will do the trick.

Upvotes: 60

Rufus Shinra
Rufus Shinra

Reputation: 393

Like in matlab just add a ; (semicolon) to the end of a line you don't want output to the terminal.

Upvotes: 19

Related Questions