2

I took a look at a similar question , but the answer as well as the linked question within didn't match my exact problem.

Assume, that I have several Matlab files that are executed by a program. During the execution of the code, I receive multiple outputs in the command window, which I want to get rid of. Of course, I could just grep all disp and printf commands, no problem. However, there is also the possibility, that certain computations print something without Matlab giving me a warning for a missing semicolon. An example would be

function dummy1
norm(1)
end

Which would print 1 to the command window, but Matlab does not give me a warning for a missing semicolon as it would be the case for

function dummy2
1+1
end

Is there a way to detect the position of the command that prints to command window?

Thomas
  • 1,199
  • 1
  • 14
  • 29
  • This might be one of the few cases where I would use [`evalc`](http://ch.mathworks.com/help/matlab/ref/evalc.html) to suppress all output to the command line in the first place. This way you can call your main function like `evalc('main.m');`. Note that `diary`, `more` and `input` are disabled when using `evalc`. This does not answer your question but solves your initial *problem*. – Matt Jul 05 '16 at 19:39

1 Answers1

0

There's no need to over-complicate it. Just place some breakpoints in your code and step through until you find those lines that produce unwanted output. Then suppress the output with ;. The best practice is to never omit ;. If you want to display something quickly, use commands like disp instead.

Furthermore, you should get used to logging everything through a proper logger, like e.g. log4j. That gives you fine-grained control over what you actually log and where via a simple config (and can also be changed programmatically). If you had used it, it would not be a problem for you to find out which log message is printed where because you'd see the component name that printed it.

nirvana-msu
  • 3,877
  • 2
  • 19
  • 28