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?
MATLAB runs the function using the first run command in the list. For example, click Run to run myfunction using the command result = myfunction(1:10,5) . MATLAB displays the result in the Command Window. To run the function using a different run command from the list, click Run and select the desired command.
To start MATLAB® on Linux platforms, type matlab at the operating system prompt. If you did not set up symbolic links in the installation procedure, then type matlabroot /bin/matlab . matlabroot is the name of the folder in which you installed MATLAB.
To run a MATLAB script from the the command line, use MATLAB's -r option, as in this example which runs the Matlab script my_simulation. m from the current directory. Note that the MATLAB script that you run should have an exit command in it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With