How do I call Matlab in a script on Windows?

I'm working on a project that uses several languages:

  • SQL for querying a database
  • Perl/Ruby for quick-and-dirty processing of the data from the database and some other bookkeeping
  • Matlab for matrix-oriented computations
  • Various statistics languages (SAS/R/SPSS) for processing the Matlab output

Each language fits its niche well and we already have a fair amount of code in each. Right now, there's a lot of manual work to run all these steps that would be much better scripted. I've already done this on Linux, and it works relatively well.

On Linux:

matlab -nosplash -nodesktop -r "command"

or

echo "command" | matlab -nosplash -nodesktop

...opens Matlab in a "command line" mode. (That is, no windows are created -- it just reads from STDIN, executes, and outputs to STDOUT/STDERR.) My problem is that on Windows (XP and 7), this same code opens up a window and doesn't read from / write to the command line. It just stares me blankly in the face, totally ignoring STDIN and STDOUT.

How can I script running Matlab commands on Windows? I basically want something that will do:

ruby database_query.rb
perl legacy_code.pl
ruby other_stuff.rb
matlab processing_step_1.m
matlab processing_step_2.m
# etc, etc.

I've found out that Matlab has an -automation flag on Windows to start an "automation server". That sounds like overkill for my purposes, and I'd like something that works on both platforms.

What options do I have for automating Matlab in this workflow?

Answers


matlab -nosplash -nodesktop -r "command"

works on Windows as well. Yes, it opens another window, but it's not a problem. I run it in a batch mode from Java wrapper on Tomcat server and there were no issues. Put all commands into a script file, don't forget to close the session with exit command, and use -r flag. Also you can find -noFigureWindows and -wait parameters useful. And it works on both Windows and Unix. You can use platform-specific flags, if some are not supported they will be ignored.

Start MATLAB program (Windows platforms)

There is also a way to hide matlab window with C library. See engSetVisible.


Need Your Help

Catching errors when logging with SocketHandler in Python

python sockets exception-handling mod-python

My web application runs on multpile apache instances and I am having multiprocess logging issues because of this. I am currently using a SocketHandler for logging to a daemon using SocketServer that