is there a way to run a matlab script from linux command line?
For instance, I have the following simple script "test.m":
x = [1,2,3];
y = [2;3;4];
prod = x*y
~$ matlab test.m
~$ python test.py
In order to run a script you can open Matlab (you can prevent run it without the GUI using
-nodesktop flags), then run the script using the
run command, and finally close matlab using
You can do all this from a terminal with a single instruction:
matlab -nodisplay -nosplash -nodesktop -r "run('path/to/your/script.m');exit;"
However Matlab outputs the welcome message to the console before running your script. To get rid of the welcome message just skip the first 11 lines (10 depending on your Matlab version) using
tail -n +11
So your final instruction will be:
matlab -nodisplay -nosplash -nodesktop -r "run('path/to/your/script.m');exit;" | tail -n +11