Matlab从Linux命令行执行脚本 [英] matlab execute script from command linux line

查看:73
本文介绍了Matlab从Linux命令行执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以从Linux命令行运行Matlab脚本?例如,我有以下简单的脚本"test.m":

is there a way to run a matlab script from linux command line? For instance, I have the following simple script "test.m":

x = [1,2,3];
y = [2;3;4];

prod = x*y
disp(prod)

所以我想要的是能够从linux命令行执行该脚本而无需打开matlab GUI或matlab命令行.也就是说,我希望这样:

So what I want is to be able to execute that script from the linux command line without opening the matlab GUI or the matlab command line. That is, I expect something like that:

~$ matlab test.m

我希望在linux命令行上看到产品的结果.

and I expect to see the result of the product on the linux command line.

我知道您可以使用python这样的方式

I know that you can do that with python e.g.,

~$ python test.py

但想知道是否可以用 matlab 实现同样的效果.

but was wondering if the same can be achieved with matlab.

推荐答案

要运行脚本,您可以打开Matlab(您可以使用 -nodisplay 防止在没有GUI的情况下运行该脚本-nodesktop 标志),然后使用 run 命令运行脚本,最后使用 exit 关闭matlab.

In order to run a script you can open Matlab (you can prevent run it without the GUI using -nodisplay and -nodesktop flags), then run the script using the run command, and finally close matlab using exit.

您可以通过一条指令在终端上完成所有操作:

You can do all this from a terminal with a single instruction:

matlab -nodisplay -nosplash -nodesktop -r "run('path/to/your/script.m');exit;"

但是,在运行脚本之前,Matlab将欢迎消息输出到控制台.要摆脱欢迎消息,只需使用 tail -n +11

However Matlab outputs the welcome message to the console before running your script. To get rid of the welcome message just skip the first 11 lines (10 depending on your Matlab version) using tail -n +11

因此,您的最终指示将是:

So your final instruction will be:

matlab -nodisplay -nosplash -nodesktop -r "run('path/to/your/script.m');exit;" | tail -n +11

这篇关于Matlab从Linux命令行执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆