How to call MATLAB functions from the Linux command line?

前端 未结 8 854
一整个雨季
一整个雨季 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:18

    You can run an arbitrary function from the commandline by passing a command to Matlab, like this:

    matlab -nodisplay -r "funcname arg1 arg2 arg3 argN"
    

    This will execute the Matlab command funcname('arg1', 'arg2', 'arg3', 'argN'). Ergo, all arguments will be passed as strings and your function needs to handle this, but then again, this applies to command-line options in any other language as well.

    0 讨论(0)
  • 2020-12-12 15:19

    You could compile myfile into a standalone program and run that instead. Use Matlab's compiler mcc for that (if you have it), more information is provided in this question.

    This answer was copied from my answer to another question.

    0 讨论(0)
提交回复
热议问题