PDA

查看完整版本 : 如何从Linux命令行调用MATLAB函数?


poster
2019-12-10, 20:30
基本上我有一个m文件,看起来像

function Z=myfunc() % Do some calculations dlmwrite('result.out',Z,','); end 我只想从命令行执行它而不进入MATLAB。我尝试了几个选项( -nodisplay , -nodesktop , -nojvm , -r等),它们都-nojvm 。我最终进入MATLAB,必须输入“ quit”退出。

解决办法是什么?



回答:

MATLAB (http://en.wikipedia.org/wiki/MATLAB)可以运行脚本,但不能从命令行运行函数。这是我的工作:

文件matlab_batcher.sh :

#!/bin/sh matlab_exec=matlab X="${1}(${2})" echo ${X} > matlab_command_${2}.m cat matlab_command_${2}.m ${matlab_exec} -nojvm -nodisplay -nosplash < matlab_command_${2}.m rm matlab_command_${2}.m 输入以下内容进行调用:

./matlab_batcher.sh myfunction myinput

更多&回答... (https://stackoverflow.com/questions/2001183)