将 Matlab 命令行脚本错误保存到日志
Save Matlab command line script errors to a log
我在服务器集群上使用 Matlab,因此我没有显示并通过命令行使用它。 运行 脚本适用于
matlab -nodesktop -nosplash my_script
执行my_script
后为了将输出保存到日志并退出Matlab,我修改了命令如下:
matlab -nodesktop -nosplash -r "try, my_script; end, quit force" | tee simple.log
但是在Matlab Desktop版本中显示的错误信息并没有在日志中显示,这使得调试非常困难。
有没有办法将带有错误消息的matlabs输出存储在日志中?
问答 here 使我找到了解决方案(为了便于阅读,分为两行):
matlab -nosplash -nodesktop -r
"try, my_script; catch e, disp(getReport(e)), end, quit force" | tee my_.log
我忘记的一件简单的事情是 try
吞下了异常的错误。 catch e, disp(getReport(e))
照常显示错误消息,即使带有行号。 tee simple.log
假设您在 Linux 上 运行,请参阅这些 command line arguments。要将 matlab 的输出放入文件中,您可以调用
matlab -nosplash -nodesktop -logfile my.log -r "try; ...; catch e;.. "
-logfile filename
Copy Command Window output, including error reports, into filename, specified as a string.
我在服务器集群上使用 Matlab,因此我没有显示并通过命令行使用它。 运行 脚本适用于
matlab -nodesktop -nosplash my_script
执行my_script
后为了将输出保存到日志并退出Matlab,我修改了命令如下:
matlab -nodesktop -nosplash -r "try, my_script; end, quit force" | tee simple.log
但是在Matlab Desktop版本中显示的错误信息并没有在日志中显示,这使得调试非常困难。
有没有办法将带有错误消息的matlabs输出存储在日志中?
问答 here 使我找到了解决方案(为了便于阅读,分为两行):
matlab -nosplash -nodesktop -r
"try, my_script; catch e, disp(getReport(e)), end, quit force" | tee my_.log
我忘记的一件简单的事情是 try
吞下了异常的错误。 catch e, disp(getReport(e))
照常显示错误消息,即使带有行号。 tee simple.log
假设您在 Linux 上 运行,请参阅这些 command line arguments。要将 matlab 的输出放入文件中,您可以调用
matlab -nosplash -nodesktop -logfile my.log -r "try; ...; catch e;.. "
-logfile filename
Copy Command Window output, including error reports, into filename, specified as a string.