Azzera filtri
Azzera filtri

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

26 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Walter Roberson
Walter Roberson il 27 Gen 2016
matlab -r -nojvm -nodisplay -nodesktop -nosplash "try; mat_script; catch; end; quit;"
  2 Commenti
Brando Miranda
Brando Miranda il 27 Gen 2016
thats not fully in the format that I requested because its unclear how to pass command line arguments.
Walter Roberson
Walter Roberson il 28 Gen 2016
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.

Accedi per commentare.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by