Home > Code > MatlabDispatch

MatlabDispatch

July 8th, 2007

MatlabDispatch is a solution to quickly control one Matlab session from another.  It began when I was dissatisfied with the performance of the ActiveX protocol for communicating with the Matlab Automation Server; I wanted a way to simultaneously control two Matlab sessions (on a shiny new Core2Duo) and circumvent the single-threaded nature of Matlab.

This package solves the following problems with the ActiveX protocol:

  • It is a universal method (via Java), so it is not limited to Windows operating systems
  • Allows for simultaneous execution of multiple Matlab sessions (the Automation server pauses the client until the server returns, effectively disallowing any performance gains)
  • Fast return of dispatched executions.  Initialising a command on the remote server should return control to the client in ~0.5ms (though longer if data is passed); cf ~5ms for equivalent Execute command over ActiveX.
  • True threading of commands, so that network delay etc is captured in the JVM and should not affect the client Matlab session.
  • RMI protocol should allow for the server to be anywhere on the network (not just the local machine), though I have not personally tested this.

Installation requires adding MatlabDispatch.jar (in MatlabDispatch/dist) or the classes directory (MatlabDispatch/build/classes) to the java path, either via the ‘javaaddpath’ command or in your classpath.txt (‘edit classpath.txt’, then restart Matlab).  It is recommended that you read the help for javaaddpath and javaclasspath to understand the difference between these two options.

The function createRMIServer contains a simple example of how to set up an RMI client/server pair using the convenience of the ActiveX protocol, but will only work under Windows.  Please read the help for that function to learn more about the package and how to get it working on other operating systems.

The folder MatlabDispatch is a Netbeans 5.5 project folder to facilitate editing and/or recompiling the Java source code. It depends on the included MatlabControl class to execute Matlab commands from the JVM, courtesy Kamin Whitehouse formerly of UC Berkeley, over the undocumented package com.mathworks.jmi.

For an advanced understanding on how this works, please refer to the Java RMI documentation, eg: http://java.sun.com/docs/books/tutorial/rmi/index.html

This is available from the MatlabDispatch.git repository.

Categories: Code