Run Matlab in Linux without graphical environment?

后端 未结 5 1230
情深已故
情深已故 2021-02-04 07:54

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 envir

5条回答
  •  无人共我
    2021-02-04 08:08

    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.

提交回复
热议问题