简体   繁体   English

从 linux 命令行运行 Matlab function — 语法错误?

[英]Running Matlab function from linux command line — syntax error?

I have a matlab function checkMembraneSpline.m , and I want to run this in the command line using the matlab command.我有一个 matlab function checkMembraneSpline.m ,我想使用 matlab 命令在命令行中运行它。 I tried the following我尝试了以下

matlab -r -nodisplay -nojvm "checkMembraneSpline(10,1000,'',100,500,2.5); catch; end; quit"

which returns this cryptic error:它返回这个神秘的错误:

/opt/apps/rhel7/matlabR2019a/bin/matlab: eval: line 1734: syntax error near unexpected token `('
/opt/apps/rhel7/matlabR2019a/bin/matlab: eval: line 1734: `exec  "/admin/apps/rhel7/matlabR2019a/bin/glnxa64/MATLAB"  -r "-nodisplay" checkMembraneSpline(10,1000,'',100,500,2.5); catch; end; quit -nojvm'

However, when I launch matlab by doing matlab -nojvm -nodisplay and running the function from there by但是,当我通过执行matlab -nojvm -nodisplay并从那里运行 function 来启动 matlab 时

>>> checkMembraneSpline(10,1000,'',100,500,2.5)

it works.有用。 I suspected it was something to do with the quotation marks, but switching " with ' also doesn't work. What am I missing?我怀疑这与引号有关,但是用'切换"也不起作用。我错过了什么?

The statement has to come right after the -r switch:该语句必须紧跟在-r开关之后:

matlab -nodisplay -nojvm -r "checkMembraneSpline(10,1000,'',100,500,2.5); catch; end; quit"

If you have a newer version of MATLAB, use the -batch switch instead:如果您有更新版本的 MATLAB,请改用-batch开关:

matlab -nojvm -batch "checkMembraneSpline(10,1000,'',100,500,2.5);"

With this new switch you don't need to have an exit call, it always quits after competing the statement.使用这个新开关,您不需要exit调用,它总是在竞争语句后退出。 Therefore, it is also not necessary to catch errors.因此,也没有必要捕获错误。 Output is put into the terminal by default. Output 默认放入终端。 Much simpler!简单多了!

Reference: https://www.mathworks.com/help/matlab/ref/matlablinux.html参考: https://www.mathworks.com/help/matlab/ref/matlablinux.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM