How to turn off backtrace in warning message while still showing immediately?
42 次查看(过去 30 天)
显示 更早的评论
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 个评论
Limabean
2021-9-23
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
2021-9-24
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.
回答(1 个)
Walter Roberson
2018-7-1
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!