MATLAB: Can I give MATLAB commands in series from the OS command prompt

command line

My question seems like this:
I want to keep only one MATLAB instance open, and then feed the m-file or "Matlab command" to Matlab from system command line or bat/bash file.
(I do NOT want to call m-file or "Matlab command" from Matlab command window for some reason)

Best Answer

You can call into the MATLAB Engine or invoke the MATLAB COM Automation Server to control the creation of a single MATLAB process to execute multiple commands. Note that this involves some programming on your behalf in languages such as C/C++ which you may then compile into an executable and call from the system shell. The reason you cannot do this directly from the shell, is because shell commands - by principle - launch an executable and cannot call into runtime libraries directly (which is what executing individual MATLAB functions in an existing MATLAB session would entail).