Run Matlab in Linux without graphical environment?
I am going to run a Matlab program in a remote Linux server using SSH. I was wondering how to run Matlab in Linux with only command line, which means there is no graphical environment?
Start MatLab with the the following flags
matlab -nodesktop -nojvm -nosplash
-nodesktop prevents the desktop
-nojvm prevents starting of the java virtual machine
-nosplash prevents the start-up splash screen.
Note, that, as Li-aung Yip noted in the comments, Mathworks does not recommend to use the -nojvm flag.
The command is matlab -nodesktop.
Then -nodesktop and -nosplash are unnecessary. They don't make sense in text mode.
It's probably not a good idea to add -nojvm unless you have a separate good reason to do so. Without the JVM, you lose some functionality whose absence might lead to confusion later on. Source: same link as above. On top of -nodisplay, it doesn't make your non-graphical Matlab session any less graphical.
Here are a couple of ways to run commands non-interactively.
matlab -nodisplay < myScript.m
Put exit as e.g. the last command in myScript.m.
matlab -nodisplay -r "try, myFunction(); catch e, disp(getReport(e)), exit(7), end, exit()"
The second way is preferable, because e.g. if there is an error in the middle of the code, then the second way will print an error message and exit with a non-zero code. Whereas the first way is equivalent to typing the commands in directly, regardless of what Matlab says (which might be error messages).
In case the next question is "how to suppress the welcome message in text-mode Matlab?", it seems there is NO good way to get rid of it.