在批处理模式下运行Matlab [英] run Matlab in batch mode
问题描述
在我看来,有两种方式在批处理模式下运行Matlab:
It seems to me that there are two ways to run Matlab in batch mode:
第一个:
unset DISPLAY
matlab > matlab.out 2>&1 << EOF
plot(1:10)
print file
exit
EOF
b $ b
第二个使用选项-r MATLAB_command:
The second one uses option "-r MATLAB_command":
matlab -nojvm -nosplash -r MyCommand
这两个是等价的吗?
在第一种方法中,<< EOF和最后一个EOF是什么意思?
What does "<< EOF" and the last "EOF" mean in the first method?
感谢和问候!
推荐答案
第一种方法简单地重定向标准输出> matlab.out
和标准错误 2>& 1
到文件 matlab.out
。
The first method simply redirects the standard output > matlab.out
and the standard error 2>&1
to the file matlab.out
.
然后使用 heredoc 将输入传递给MATLAB的方法(这不是特定于MATLAB的,它是一个将多行作为输入传递给命令行程序的方法)。
Then it uses the heredoc way of passing input to MATLAB (this is not specific to MATLAB, it is a method of passing multiple lines as input to command line programs in general).
语法是<
您可以在shell上尝试:
The syntax is <<
followed by an unique identifier, then your text, finally the unique id to finish.
You can try this on the shell:
cat << END
some
text
multiple lines
END
使用 -r
选项的第二种方法启动MATLAB并立即执行语句。它可以是一些命令或在路径上找到的脚本或函数的名称。
它相当于做类似于:
The second method of using the -r
option starts MATLAB and execute the statement passed immediately. It could be some commands or the name of a script or function found on the path.
It is equivalent to doing something like:
python -c "print 'hello world'"
请参阅第页,了解其他开始选项的列表。
Refer to this page for a list of the other start options.
这篇关于在批处理模式下运行Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!