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

38 visualizzazioni (ultimi 30 giorni)
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?
  2 Commenti
Limabean
Limabean il 23 Set 2021
My trace is often over ten lines long. I wish there was an option to only list the one line where the warning happened. that one line would let me click the link to go to the problem area.
Walter Roberson
Walter Roberson il 24 Set 2021
If you already know the places the warnings might occur and can reprogram the warning() call, then you can construct something that uses fprintf to fid 2 and emits an HTML HREF to a URI that starts with "matlab:" that is a command to do something appropriate such as open the editor to that file line.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 1 Lug 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