I want to execute a matlab script from the terminal.
Although there are many questions (e.g.: here or here) and answers out there, I still could not find a solution how to get it working.
I'm currently in the same directory as a test.m
script and following the answers found on the internet, I have tried to start matlab using:
matlab -nodesktop -nodisplay -nosplash -r test
From the matlab help, I think the right approach would be to use the -batch flag
matlab -batch "test"
but also this does not work.
I also tried several alternatives:
matlab -nodesktop -nodisplay -nosplash -r "test"
matlab -nodesktop -nodisplay -nosplash -r "test.m"
matlab -nodesktop -nodisplay -nosplash -batch "test.m"
matlab -nodesktop -nodisplay -nosplash -r "run('test')"
matlab -nodesktop -nodisplay -nosplash -r "run('test.m')"
matlab -nodesktop -nodisplay -nosplash -r "run('/absolut/path/test')"
However, I always get the following error message:
< M A T L A B (R) >
Copyright 1984-2020 The MathWorks, Inc.
R2020a Update 3 (9.8.0.1396136) 64-bit (glnxa64)
May 27, 2020
To get started, type doc.
For product information, visit www.mathworks.com.
Warning: Command line argument -r cannot be combined with subsequent -r
argument.
What is working on Linux is
matlab -nodisplay < test.m
Edit: I tested it today on windows and
matlab -batch test
works on windows.