Interoperating between Matlab and C#

Solution 1:

Beginning with the R2009a release of MATLAB, .NET objects can be accessed from MATLAB:

http://www.mathworks.com/help/techdoc/matlab_external/brpb5k6.html

In older versions of MATLAB, it is possible to access .NET objects from MATLAB using CCW:

http://www.mathworks.com/support/solutions/data/1-5U8HND.html?solution=1-5U8HND

and the MATLAB engine from .NET:

http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_external/f135590.html#f135616

You can also use the MATLAB Builder NE to wrap m-code into .NET assemblies.

http://www.mathworks.com/products/netbuilder/

Solution 2:

Yes, quite possible. Though I ended up using the C interface and calling into that using a mixed-mode DLL (and getting C# to call into that... but that was because I was also interfacing with some other C code). It's quite straightforward. On computers where you want to run your program, you'll need to install Matlab Runtime MCRInstaller.exe.

edit: removed broken link

Solution 3:

Yes, I managed to do that and it was mostly painless.

You'd have to compile your MATLAB code for .NET (as explained in pervious answers), run MCR installer, reference MWArray.dll and the complied code dll in your .NET project and off you go.

The only annoyance was the casting (and sometimes multiple castings!) that the interface forces on you (using explicit in the cast operators)

Solution 4:

There is a free and open source .NET wrapper for Matlab, and it is very simple: http://www.codeproject.com/KB/dotnet/matlabeng.aspx

I use this.