How to suppress the command window output of a function, that contains non-terminated statements (no ;s at the end), *without* changing the function itself

31 views (last 30 days)
Summary: Way to prevent the command window output of an entire function, without editing the function
If I run a function, let's say...
function ControllableOutput = UneditableFunction(LowerBound, UpperBound)
FillsTheControlWindowWithRubbish = linspace(LowerBound,UpperBound,500)
ControllableOutput = 2*FillsTheControlWindowWithRubbish;
end
...By calling it from a script / the command window via ...
ControllableOutput = UneditableFunction(X1,X2);
...Even if I terminate the statement - which suppresses the output of ControllableOutput from the command window, UneditableFunction will always output FillsTheControlWindowWithRubbish onto the control window, whether the function call is terminated or not. This is annoying and slows the execution time down considerably. Unfortunately in this case, I can't edit the function UneditableFunction, it would also be useful to know if there's a way of doing this.
.
Some backstory - I'm working with some code that's in the non-editable / openable format, with some non-terminated statements inside it. Unfortunately that means that every time I run UneditableFunction it takes ages uselessly filling the command window with numbers. It's especially wonderful as the top level code searches for regression so runs UneditableFunction iteratively. Fun.
If you know a half fix, like how to freeze the output to the command window for a bit, or something like the 'invisible' function type but for command window outputs, that would go along way to speeding this up.

Accepted Answer

Steven Lord
Steven Lord on 19 Aug 2015
Take a look at the EVALC function. If you're using solely to capture the text that would normally be displayed when a function is executed, and NOT using it to create variables like so many people try to use EVAL, it is IMO the "safest" of the EVAL family of functions.
  2 Comments
Geeeeeeek
Geeeeeeek on 20 Aug 2015
Thanks! I'm using the equivalent of:
evalc('ControllableOutput = UneditableFunction(0,5)');
And it works perfectly :)
No worries, I'm had the evils of the eval functions drummed into me.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!