How can I pass input parameters to a MATLAB script from a Bash shell in Unix with arguments without opening MATLAB shell?

21 次查看(过去 30 天)
I wanted to run something like:
matlab -no_gui -no_matlab_shell my_matlab_script.m param1 param2 param3 ...
the idea was that I wanted MATLAB to print to STDOUT or somewhere the outputs of my program without opening the user interfaces. However, I had not have luck.
What I did was to get a similar behaviour was:
-bash-4.1$ matlab -r -nojvm -nodisplay -nosplash "run mat_script.m"
and I got out:
< M A T L A B (R) >
Copyright 1984-2015 The MathWorks, Inc.
R2015a (8.5.0.197613) 64-bit (glnxa64)
February 12, 2015
For online documentation, see http://www.mathworks.com/support
For product information, visit www.mathworks.com.
Academic License
Error using run (line 28)
Not enough input arguments.
which is obviously not what I wanted because
  1. It didn't run my script.
  2. It opened matlab shell.
So I wasn't sure why that happened. I read the docs and it says -r runs the command given to MATLAB so I a not sure why it didn't run it. However, once in the session it did obey me once I wrote:
run mat_script.m
so I am not sure whats going on.

回答(1 个)

Walter Roberson
Walter Roberson 2016-1-27
matlab -r -nojvm -nodisplay -nodesktop -nosplash "try; mat_script; catch; end; quit;"
  2 个评论
Walter Roberson
Walter Roberson 2016-1-28
matlab -r -nojvm -nodisplay -nodesktop -nosplash "try; my_matlab_script param1 param2 param3 ...; catch; end; quit;"
Caution: you cannot pass parameters to a script, only to a function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by