Is there a recommended way to call Matlab repeatedly from an external program?

I repeatedly call matlab script MyMatlabScript from another program (written in Erlang). I do this using a batch file containing the following:

 matlab -nodesktop -nosplash -wait -r "addpath('C:/...'); MyMatlabScript; %quit;" 

This means that Matlab should be run every time I run the batch script file. It works, but slowly *.

To improve performance, I would like to be able to run Matlab once, and then somehow, using Erlang or the batch version of the script, re-initiate my Matlab script using this single Matlab instance.

Can this be done?

Note. I am using Matlab 7.8.0 (R2009a) on Windows7.

* Extra slow due to the problem described here !

+4
source share
3 answers

I don't know if messaging in Matlab is a viable option, but I would like to suggest an alternative. Matlab has a timer object that allows you to specify a callback function. At regular intervals, the Matlab callback function can check for a file that is being modified by Erlang. The modified file starts the required Matlab procedure. Well, this is not a “haute cuisine” in terms of programming style, but it should do the job.

+2
source

It is not simple. But you can try using the COM automation server interface in MATLAB. You need to have an Erlang library to interact with COM automation servers. Using this interface, you can create an automation server and then continue to send commands to it. Documentation can be found at http://www.mathworks.com/help/matlab/call-matlab-com-automation-server.html . There are examples in the documentation that use Visual Basic code.

+6
source

I have experience only in this. There are three main options:

  • Erlang command line calls Matlab with os: cmd ()

  • Writing a protocol that requires two applications to be separate and exchange data over tcpip. The advantage is that Erlang is now a server, or vice versa, however you encode it. Challenge is a protocol code in Matlab, Erlang is specially built for it.

  • Make a system channel. If you stick to windows (NamedSystemPipe), you really shouldn't have a problem finding documents on how to do this.

I prefer method 3 for local comm only and 2 for any network connection. Using 1 gives you absolute minimal flexibility. More, but since you ask, this is what I recommend.

And best of all, the “slow” problem is gone without using 1.

+1
source

All Articles