Lab# is a .Net library written in C# 2.0 to interact with MATLAB® from any .Net application.
Technically Lab# is a wrapper around the
MATLAB engine API.
This API allow you to get and put matrices in MATLAB.
Version 1.0 Alpha 1 source code
Latest version is always in SVN, the URL is : https://svn.sourceforge.net/svnroot/labsharp
.
If you don't have any SVN client, under windows
Tortoise SVN is a good choice
(Integrated into the shell).
// This exemple create an array with the values of the function // f(x) = sin(x / 10); on the [0..100] range and display it in matlab. using System; using LabSharp; class Program { static void Main(string[] args) { double[] sin = new double[100]; for (int i = 0; i < sin.Length; i++) { sin[i] = Math.Sin(i / 10.0); } using (Engine eng = Engine.Open()) { eng.SetVariable("sin", sin); eng.Eval("plot(sin); figure(gcf)"); } } }
// This exemple fill an array with random values, send it to MATLAB and use // MATLAB to calculate the mean value, then display the result in C#. using System; using LabSharp; class Program { static void Main(string[] args) { Random rnd = new Random(); double[] dataArray = new double[100]; for (int i = 0; i < dataArray.Length; i++) { dataArray[i] = rnd.NextDouble() * 100; } using (Engine eng = Engine.Open()) { eng.SetVariable("data", dataArray); eng.Eval("data_mean = mean(data)"); Console.WriteLine("The mean is : {0}", eng.GetVariable<double>("data_mean")); // Clean up eng.Eval("clear data"); eng.Eval("clear data_mean"); } Console.ReadKey(); } }
MWArray
class. But this project was started before, and i still
think that it have some advantages :
MWArray
like Cell Arrays,
and an official support from MathWorks.
By Roncaglia Julien (black-fox)