2
votes

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?

1
This might be one of the few cases where I would use evalc 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

1 Answers

0
votes

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.