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!
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);
There are several methods.
First, you can use COM as a bridge. see
http://www.mathworks.nl/matlabcentral/newsreader/view_thread/153172
http://topic.csdn.net/u/20090402/16/6db37a24-648c-4f8d-a353-42eab4c4bcbe.html
http://www.sciencenet.cn/m/user_content.aspx?id=304113
Second, you can use matlab-net-API. see
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/f16-35614.html#brxerx8-1
and
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/exampleindex.html