Run Matlab in Linux without graphical environment?

后端 未结 5 1231
情深已故
情深已故 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:34

    Putting the other answers together plus some more error handling, save the following as an executable file matlab-headless:

    #/usr/bin/env bash
    
    # restore the "sane" state of the terminal at the end
    # otherwise interrupting the process may leave the terminal messed up
    trap 'stty sane' EXIT
    command="try, $1;, catch e, stack=getReport(e); fprintf(1, '%s\n', stack);, end, exit;"
    
    # tail gets rid of the welcome message banner
    matlab -nodisplay -nodesktop -nosplash -r "$command" | tail -n +11
    

    Now you can run a Matlab command as:

    matlab-headless "somecommand('bla', 42)"
    

提交回复
热议问题