matlab cmd文件,Matlab:从命令行运行m文件

本文介绍了一种在MATLAB中使用try-catch块进行错误处理的方法,并展示了如何利用MExeption的getReport方法获取完整的错误信息。此外,还提供了将MATLAB控制台输出记录到文件的方法,以便在Windows命令提示符窗口中查看。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Thanks to malat. Your comment helped me.

But I want to add my try-catch block, as I found the MExeption method getReport() that returns the whole error message and prints it to the matlab console.

Additionally I printed the filename as this compilation is part of a batch script that calls matlab.

try

some_code

...

catch message

display(['ERROR in file: ' message.stack.file])

display(['ERROR: ' getReport(message)])

end;

For a false model name passed to legacy code generation method, the output would look like:

ERROR in file: C:\..\..\..

ERROR: Undefined function or variable 'modelname'.

Error in sub-m-file (line 63)

legacy_code( 'slblock_generate', specs, modelname);

Error in m-file (line 11)

sub-m-file

Error in run (line 63)

evalin('caller', [script ';']);

Finally, to display the output at the windows command prompt window, just log the matlab console to a file with -logfile logfile.txt (use additionally -wait) and call the batch command type logfile.txt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值