Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run Matlab in batch mode

It seems to me that there are two ways to run Matlab in batch mode:

the first one:

unset DISPLAY  
matlab > matlab.out 2>&1 << EOF  
plot(1:10)  
print file  
exit  
EOF

The second one uses option "-r MATLAB_command":

matlab -nojvm -nosplash -r MyCommand   

Are these two equivalent?

What does "<< EOF" and the last "EOF" mean in the first method?

Thanks and regards!

like image 307
Tim Avatar asked Dec 07 '09 04:12

Tim


People also ask

What is batch mode in MATLAB?

Offload execution of functions to run in the background. Use batch jobs to off-load the execution of long-running computations in the background. For batch jobs, MATLAB® can be closed on the client, and the client can be shut down when the batch job is submitted to another computer or cluster.

Can MATLAB be run from command line?

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.

How do I run a MATLAB script line by line?

On the Editor or Live Editor tab, in the Section section, select Run to End. Run to a specific line of code and pause. Click the Run to Here button to the left of the line. If the selected line cannot be reached, MATLAB continues running until the end of the file is reached or a breakpoint is encountered.


1 Answers

The first method simply redirects the standard output > matlab.out and the standard error 2>&1 to the file matlab.out.

Then it uses the heredoc way of passing input to MATLAB (this is not specific to MATLAB, it is a method of passing multiple lines as input to command line programs in general).

The syntax is << followed by an unique identifier, then your text, finally the unique id to finish. You can try this on the shell:

cat << END
some
text
multiple lines
END

The second method of using the -r option starts MATLAB and execute the statement passed immediately. It could be some commands or the name of a script or function found on the path. It is equivalent to doing something like:

python -c "print 'hello world'"

Refer to this page for a list of the other start options.

like image 169
Amro Avatar answered Oct 24 '22 09:10

Amro