Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Thanks.

like image 625
Lei Avatar asked Jun 15 '12 07:06

Lei


3 Answers

Start MatLab with 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.

like image 198
H.Muster Avatar answered Sep 18 '22 19:09

H.Muster


matlab -nodisplay

See here about -nodisplay.

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.

Way 1:

matlab -nodisplay < myScript.m

Put exit as e.g. the last command in myScript.m.

Way 2:

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.

like image 28
Evgeni Sergeev Avatar answered Sep 20 '22 19:09

Evgeni Sergeev


The command is matlab -nodesktop.

http://www.mathworks.de/help/techdoc/ref/matlabunix.html

like image 25
Herr von Wurst Avatar answered Sep 21 '22 19:09

Herr von Wurst