Log Error and Warning Messages to Text File
45 次查看(过去 30 天)
显示 更早的评论
Is there a way to log error and warning messages to a text file? I cannot use the "diary" function since I am running Matlab within Cameo System Modeler and don't have a command window.
3 个评论
Walter Roberson
2022-6-17
I would suggest using an absolute path for the diary file name, as you might not be cd to where you expect.
回答(2 个)
Jan
2022-6-17
You can catch errors using try-catch and write the messages whereever you want.
Redirecting warnings is more tricky. I use my own warning functions, but warnings created by toolbox functions are harder to catch. You can shadow the built-in function "warning" by a user-defined function, which is store in a folder on top of Matlab's path:
function warning(varargin) % [UNTESTED CODE!!!]
Msg = evalc('builtin(''warning'', varargin{:})');
... % ==> write the message to your log file
end
This looks ugly, but maybe it works.
I do not trust code, which shows warnings. After inverting a matrix, I check the lastwarn state and drop an error in case of problems. If this happens repeatedly, I add some code to check condition of the matrix before the inverting. So I do not used code for productive work, which drops warnings.
0 个评论
Sonoma Rich
2022-6-17
1 个评论
Jan
2022-6-17
Is this an answer or a comment? In the latter case, please post it in the coirresponding section for comments. Thanks.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scope Variables and Generate Names 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!