How to call MATLAB functions from the Linux comman

2019-01-21 01:48发布

Basically I have an m file which looks like

function Z=myfunc()
    % Do some calculations
    dlmwrite('result.out',Z,',');
end

I just want to execute it from the command line without getting into MATLAB. I tried several options (-nodisplay, -nodesktop, -nojvm, -r, etc.), none of them worked. I end up getting into MATLAB and have to type "quit" to exit.

What is the solution?

8条回答
SAY GOODBYE
2楼-- · 2019-01-21 02:32

MATLAB can run scripts, but not functions from the command line. This is what I do:

File 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

Call it by entering:

./matlab_batcher.sh myfunction myinput
查看更多
狗以群分
3楼-- · 2019-01-21 02:35

You can call functions like this:

matlab -r "yourFunction(0)"

查看更多
登录 后发表回答