How to call MATLAB functions from the Linux command line?

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

    Here's a simple solution that I found.

    I have a function func(var) that I wanted to run from a shell script and pass it the first argument for var. I put this in my shell script:

    matlab -nodesktop -nosplash -r "func('$1')"
    

    That worked like a treat for me. The trick is that you have to use double quotes with the "-r" command for MATLAB and use single quotes in order to pass the bash argument to MATLAB.

    Just make sure that the last line of your MATLAB script is "exit" or that you run

    matlab -nodesktop -nosplash -r "func('$1'); exit"
    

提交回复
热议问题