Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing a function's command window output

Tags:

A function I'm using has display() in it (or other things that display messages on command window), so it outputs a lot of things (x 1200) on command line when I run my code, which makes things hard to track and observe.

Is there a way to suppress the output of this specific function? Ending the statement with semicolon obviously doesn't help.

like image 534
Ali Avatar asked Jun 12 '10 18:06

Ali


People also ask

How do I suppress the Command Window output in MATLAB?

Hear me out here, I know that to suppress output you put a semicolon at the end of a line. However even after adding the semicolon at the end of each line of my . m file Matlab is still displaying an output of the actual line itself.

Which of the following symbol suppresses a display in MATLAB?

To suppress 'ans' return of function file don't assign an output; find the variable and use disp(variable).


2 Answers

You might try wrapping the call to the function in an evalc:

evalc('out = func(arg1, arg2);'); 
like image 195
SCFrench Avatar answered Sep 22 '22 06:09

SCFrench


The easiest way is to just create a dummy function DISP/DISPLAY and place it in a private folder along with your own function:

private/disp.m

function disp(x)     return end 

myFunc.m

function myFunc()     %# ...     disp(1) end 

By placing the disp function inside a private folder, you override the built-in function with the same name, yet this version is only visible to functions in the parent directory, thus maintaining the original functionality in other places.

Make sure that you DON'T add this private folder to your path, just have myFunc.m on the path (Please read the relevant documentations)

like image 35
Amro Avatar answered Sep 21 '22 06:09

Amro