views:

39

answers:

2

Hi, Could anyone suggest a straightforward way to take a vector of numbers from MATLAB and add those numbers to a list in C# to be called upon by an event in the C# program? I've found a lot of information on the interface between the two languages, but I'm very new to c# and could use the specificity. Any suggestions welcome!

+2  A: 

If you want to call MATLAB from a C# program, use the NE Builder toolbox. There are lots of examples of how it works here.

Your MATLAB code will look something like

function y = GenerateSomeNumbers()
   y = rand(1, 10);
end

Build this into MyMatlabComponent.dll with the builder, and add a reference to this dll in your C# program.

Your C# code will look something like

using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using MyMatlabComponent;

// ...

// Inside the appropriate method
List<double> l = new List<double>();
MyMatlabComponentclass c = new MyMatlabComponentclass();
MWNumericArray m = c.GenerateSomeNumbers();
l.Add((double)m);
Richie Cotton