matlab - 如果命令行代码中出现语法错误,如何退出 MATLAB(选项 -r)
问题描述
我需要以批处理模式运行 MATLAB,并希望捕获所有可能的错误。以下代码
matlab -nojvm -nodesktop -nosplash -r "try, x=y; catch ME, disp(getReport(ME)); end; exit"
工作正常,MATLAB 正确地抱怨
Undefined function or variable 'y'.
但是,对于这样的语法错误
matlab -nojvm -nodesktop -nosplash -r "try, x:=y; catch ME, disp(getReport(ME)); end; exit"
MATLAB 说
try, x:=y; catch ME, disp(getReport(ME)); end; exit
|
Error: Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.
>>
并在命令提示符处暂停。防止这种行为的蛮力方法是
echo "exit" | matlab -nojvm -nodesktop -nosplash -r "try, x:=y; catch ME, disp(getReport(ME)); end; exit"
有没有更优雅的方法来解决这个问题?谢谢。
MATLAB 版本:9.5 (R2018b),操作系统:Linux 4.12.14 (OpenSUSE)
解决方案
推荐阅读
- python - 尝试安装pyaudio时,无论我在互联网上尝试什么,我的mac都不会
- amazon-web-services - 如何在 AWS 中查找附加到默认安全组的所有服务?
- c++ - 循环链表中不能交换尾节点和首节点
- c# - 将 JSON 解析为列表
- python - 来自 HTML 动态表单的 Django POST 请求
- sql - 如何组合值,以便在运行报告时,与它们关联的值总和为一个最终值?
- javascript - 超级账本结构:只有所有者才能访问私有数据
- python - 我尝试使用硒,但它给出了如下错误:
- laravel - 无法将令牌保存到 laravel 中的个人访问令牌表
- google-apps-script - 尝试组合多个 onEdit 功能