views:

641

answers:

4

Basically I have a m file which looks like

function Z=myfunc()

% do some calculations

dlmwrite('result.out',Z,',');

end

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

Anyone know the solution??

Thanks in advance.

+4  A: 

From MathWorks:

How do I run MATLAB in batch mode on a UNIX machine?

Adam Goode
+4  A: 

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

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

and call it by entering:

./matlab_batcher.sh myfunction myinput
Alex Cohen
What is the input here ???
ablimit
What I did is just:matlab -nojvm -nodisplay -nosplash < my_mfile.m >/dev/null 2>/dev/nullAnyway it prints some error message, but result is right.
ablimit
Yes ! It worked.Thanks Alex !
ablimit
sorry, input from the command line: $1 is the function name, $2 is the input for the function
Alex Cohen
+1  A: 

matlab -nosplash -nodesktop -logfile remoteAutocode.log -r matlabCommand

make sure matlabCommand has an exit as its last line.

Douglas Forman
A: 

nohup matlab -nodisplay -nodesktop -nojvm -nosplash -r script.m > output &

Manas