Shyamini
Shyamini

Reputation: 1

How to integrate MATLAB in to C#?

I have UIs implemented using C#.NET and image processing procedure developed in MATLAB..Hence I need to know a way of integrating MATLAB into C#.NET to use these two processes as one system.....

Upvotes: 0

Views: 3528

Answers (2)

tuncalik
tuncalik

Reputation: 1144

How to call user-defined matlab functions from within C#/.NET:

I explained it once here in detail. For this integration method you will need the Deployment Tool of matlab in order to compile your matlab functions into dll assemblies that can be referenced by C#/.NET.

To summarize, these are the steps:

1) Write your matlab functions (m files) and save them. You will call these functions from C#/.NET

2) Open Deployment Tool (deploytool) in matlab and add all the matlab m files to the package, named for example MyMatlabFunctions.prj

3) Add a class to deploy package with a name like MyMatlabClass. This class will contain the .NET translations (or compilations) of your matlab functions.

4) Build the package MyMatlabFunctions.prj with deploytool. The generated MyMatlabFunctions.dll will be referenced in our Visual Studio project.

5) Add matlab-related references (dll's) MatCode.dll and MWarray.dll to your Visual Studio project.

6) Write the C#/.NET method which calls the dll translation of your matlab functions. A simple example below: Matrix Addition (addMatrices.m)

static public void SimpleMatrixAddition()
{
    double[,] a = { { 2, 3 }, { 5, 6 }, { 8, 9 } }; //Matrix 1
    double[,] b = { { 1, 2}, { 4, 5}, { 7, 8} };    //Matrix 2

    MWNumericArray arr1 = a;
    MWNumericArray arr2 = b;

    MyMatClass obj = new MyMatClass();

    // call matlab function (addMatrices.m)
    MWArray result = (MWNumericArray)obj.addMatrices((MWArray)arr1, (MWArray)arr2);

    // display matlab matrix
    Console.WriteLine("matlab matrix:\n" + result);
    Console.ReadKey();
}

Upvotes: 0

Jamie
Jamie

Reputation: 613

Matlab Builder? http://www.mathworks.co.uk/products/netbuilder/

Upvotes: 0

Related Questions