Matlab Engine

Matlab Engine allows a stand alone C or C++ program to call Matlab to perform a calculation or execute a command. This allows data to be sent directly to Matlab, and use existing Matlab code to analyze data (and even send it back to the C++ program, for closed loop applications).

Video Example of Matlab Engine

In Unix, Matlab engine uses pipes, so the theoretical latency of sending and receiving messages to Matlab Engine should be on the order of 10s of microseconds. Thus, this should be an easy way to allow Matlab code to be used as processors or sinks, even in closed loop situations (as long as the Matlab code is fast enough, of course).

There are a couple of downsides to using Matlab Engine. On systems other than Windows, you can't attach to an existing session of Matlab (though there are ways around that, like http://www.mathworks.com/matlabcentral/fileexchange/28572-sharedmatrix), and because of how it transfer input and output, you can't simultaneously control the engine from the typical matlab terminal and the GUI, which requires some sort of terminal. 

The solution is to keep the engine running as a full client to the GUI, and input Matlab commands into the Open Ephys GUI and have them implemented in the engine (you can then save the workspace if you want to switch to full MATLAB later). This allows for full command line control over the engine, including running MATLAB GUI elements.

The second downside of Matlab, is that compiling it requires you to link to a couple of things in Matlab that are a pain and seem somewhat finicky. Hopefully this is just a problem for compilation, and will require minimal work once it's compiled. In any case, while a cursory googling will show that this is a common pain with Engine applications, it's also an eminently solvable problem.

If you have experience with Matlab Engine, or are interested in helping, feel free to contact Ryan Maloney, and of course, once I've ironed out the majority of the bugs in the code, I'll push it to GitHub.

Project Status:

A few proof of concept modifications to engdemo.cpp

Compiling with Matlab Engine Libraries and evoking Engine.

Created terminal in GUI to control Matlab Engine

Debugging sink to send buffer to Matlab

Allowing sources to be pulled from Matlab

Prettying things up