Matlab + C#

Matlab is a powerful tool for everyone that works with sensor data. Recently, I have been developing some scripts in Matlab to make sense of some sensor data because it is very handy for prototyping algorithms. The final system, however, was to be implemented in C#. I thought I would have to reimplement all my algorithms, but then I found out that it is possible to connect C# applications to Matlab in several ways. I ended up calling my Matlab scripts using the COM interface.

Matlab + C#

This is how I did it:

1) Create a project in Visual Studio

2) Right-click on References > Add Reference

3) In the COM tab select “Matlab Aplication” and click OK

4) The following code creates the COM object

MLApp.MLApp matlab = new MLApp.MLApp();

5) Now you can access all Matlab functionality through the methods provided by this object. You can send commands with the Execute method which returns a string with the console output.

Reference

Matlab Automation Server Examples

One thought on “Matlab + C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s