11

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!

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.