sodiumnitrate
sodiumnitrate

Reputation: 3131

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. 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

>>> 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?

Upvotes: 0

Views: 307

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60474

The statement has to come right after the -r switch:

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 -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. Therefore, it is also not necessary to catch errors. Output is put into the terminal by default. Much simpler!

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

Upvotes: 2

Related Questions