tags:

views:

230

answers:

2

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.

+2  A: 

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)

Amro
Better: just make it an internal function - at the bottom of the file. That way you don't pollute the namespace for anything other than this function.
Marc
I guess for a single contained function that is indeed simpler and cleaner. But in case it calls other functions across multiple files (which you want to suppress their output as well), it would be easier to maintain one single change using a private folder
Amro
+3  A: 

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

SCFrench
+1: evalc captures all output, including `fprintf` calls, and it's much less risky than creating a private `disp` that one might later forget.
Jonas

related questions