Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress the output of a command in octave?

In Octave I can suppress or hide the output of an instruction adding a semicolon to the end of a line:

octave:1> exp([0 1])
ans = [ 1.0000   2.7183 ]
octave:2> exp([0 1]);
octave:3> 

Now, how can I suppress the output if the function displays text (e.g. using disp() or print()) before returning its value? In other words, I want to be able to do this:

disp("Starting...");
% hide text the may get displayed after this point
% ...
% show all text again after this point
disp("Done!");
like image 209
andersonvom Avatar asked Nov 24 '11 17:11

andersonvom


2 Answers

You can modify the PAGER variable (which is now a function) to redirect standard output. On Unix systems, you can redirect it to /dev/null. On Windows, I tried simply redirecting to a Python program that does nothing, and it works decently. (Basically, any program that ignores the input will do)

PAGER('/dev/null');
page_screen_output(1);
page_output_immediately(1);

You can just change it back after you're done. And maybe encapsulate this whole procedure in a function.

oldpager = PAGER('/dev/null');
oldpso = page_screen_output(1);
oldpoi = page_output_immediately(1);

% Call function here

PAGER(oldpager);
page_screen_output(oldpso);
page_output_immediately(oldpoi);

You can also simply run your scripts non-interactively, and redirect the output normally.

octave script.m > /dev/null
like image 68
voithos Avatar answered Nov 22 '22 09:11

voithos


A quick hack of your problem and maybe not even worth mentioning is overloading the disp function like so:

function disp(x)
end

Then the original disp function is not called but yours instead in which no output is generated.

I also tried to somehow redirect stdout of octave, but unsuccessful. I hope that this dirty solution maybe will suffice in your situation^^

like image 37
Woltan Avatar answered Nov 22 '22 11:11

Woltan