MATLAB: How can I send commands to ‘command window’ programly

command windowpythonterminal

Hello. I want to send "commands" to matlab command window programly
  1. I opened Matlab "Command window", in mac (Linux) type 'matlab -nodesktop' in terminal.
  2. I want to send matlab commends to matlab console (command window) in another terminal, or python script.
  3. because, i want to compare the results by matlab version 2010 and 2017, so i will open both version of matlab with no desktop, and run same script in each version using python. how could i do that?

Best Answer

matlab -nodesktop -r "try; NAME_OF_SCRIPT; catch; end; quit"
is probably the easiest to use, where NAME_OF_SCRIPT is a .m file that has already been created.
If you need to work with input that is not defined ahead of time, then create a named pipe and
matlab -nodesktop < NAMED_PIPE_FILENAME
and write to the named pipe in the place you are generating the input.
If your input generation is by way of a shell derived from the Bourne Shell, then you can use exec and numbered streams and & to start background jobs that you can write to selectively by using the correct output stream number redirection. You would go through that trouble if you were working with the two different MATLAB sessions simultaneously. If you were only working with one session at a time, then you would probably instead use |& to create a co-process and use print -p to send commands to it and read -p to read from it. Which is not to neglect the power of piping the output of a shell script into MATLAB:
./SHELL_SCRIPT_NAME | matlab -nodesktop