MATLAB Answers

How to turn off backtrace in warning message while still showing immediately?

30 views (last 30 days)
Chris Gnam
Chris Gnam on 1 Jul 2018
Answered: Walter Roberson on 1 Jul 2018
I have a large simulation, and some settings and configuration files. I've also got a file that checks what the user input, and displays a series of warnings just to make sure they know the implications of their setup (This is because this is a realtime hardware-in-the-loop simulation, that can potentially run for many hours). This all works fine, however it displays the backtrace, which is completely unnecessary in this situation, and looks very cluttered.
I added the line:
warning('backtrace', 'off')
To the beginning of my "warnings file", however while it has the desired behavior of removing all of the backtraces from each warning message, it also prevents any of the warning messages from showing up until matlab has completed everything else, including the simulation itself. This completely defeats the purpose.
How can I get the warning messages to appear immediately when called, without showing the backtraces?

Answers (1)

Walter Roberson
Walter Roberson on 1 Jul 2018
Instead of using warning(), use fprintf() giving 2 as the output file identifier. For example,
fprintf(2, 'Writing 27 terabytes of Snoopy pictures!\n');
Writing to unit 2 sends to the command window with red text.
Alternately, you could look in File Exchange for cprintf() which gives some choice of colors to use.

Community Treasure Hunt

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

Start Hunting!

Translated by