I need to access Matlab functionality from within my C# applications, so I wrote this wrapper library. It provides a class to connect to a Matlab engine and a class to access Matlab matrices. It currently only supports sharing of real matrices of doubles, and it has only been tested with Matlab 6.5.
using Lydos.Matlab;
using System;
public class Example
{
static void Main()
{
Engine e = new Engine();
Matrix m = new Matrix(2, 2), n;
m[0, 0] = 0;
m[0, 1] = 1;
m[1, 0] = 2;
m[1, 1] = 3;
e.SetMatrix("m", m);
e.Evaluate("m = m + 1");
n = e.GetMatrix("m");
Console.WriteLine(m); // [0 1; 2 3]
Console.WriteLine(n); // [1 2; 3 4]
m.Dispose();
n.Dispose();
e.Close();
}
}