在没有图形环境的 Linux 中运行 Matlab?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11046470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run Matlab in Linux without graphical environment?
提问by Lei
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?
我将使用 SSH 在远程 Linux 服务器中运行一个 Matlab 程序。我想知道如何在 Linux 中仅使用命令行运行 Matlab,这意味着没有图形环境?
Thanks.
谢谢。
采纳答案by H.Muster
Start MatLab with the the following flags
使用以下标志启动 MatLab
matlab -nodesktop -nojvm -nosplash
-nodesktop
prevents the desktop-nojvm
prevents starting of the java virtual machine-nosplash
prevents the start-up splash screen.
-nodesktop
防止桌面-nojvm
阻止启动java虚拟机-nosplash
防止启动闪屏。
Note, that, as Li-aung Yip noted in the comments, Mathworks does not recommend to use the -nojvm
flag.
请注意,正如 Li-aung Yip 在评论中指出的那样,Mathworks 不建议使用该-nojvm
标志。
回答by Herr von Wurst
The command is matlab -nodesktop
.
命令是matlab -nodesktop
.
回答by Evgeni Sergeev
matlab -nodisplay
请参阅此处关于-nodisplay
.
Then -nodesktop
and -nosplash
are unnecessary. They don't make sense in text mode.
然后-nodesktop
和-nosplash
是不必要的。它们在文本模式下没有意义。
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.
添加可能不是一个好主意,-nojvm
除非您有单独的充分理由这样做。如果没有 JVM,您将失去一些功能,这些功能的缺失可能会在以后导致混淆。来源:与上面相同的链接。最重要的是-nodisplay
,它不会使您的非图形 Matlab 会话变得不那么图形化。
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
.
把exit
例如最后一个命令放在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).
第二种方式更可取,因为例如,如果代码中间出现错误,则第二种方式将打印错误消息并以非零代码退出。而第一种方法相当于直接输入命令,而不管 Matlab 说什么(可能是错误消息)。
In case the next question is "how to suppress the welcomemessage in text-mode Matlab?", it seems there is NO good way to get rid of it.
如果下一个问题是“如何在文本模式 Matlab 中抑制欢迎消息?”,似乎没有什么好方法可以摆脱它。