How to call MATLAB functions from the Linux command line?

前端 未结 8 902
一整个雨季
一整个雨季 2020-12-12 14:46

Basically I have an m file which looks like

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


        
8条回答
  •  情话喂你
    2020-12-12 15:04

    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
    

提交回复
热议问题