Main Content

Pass Complex Data to MATLAB from C# Client

This example creates complex data in a client C# program and passes it to MATLAB®. The matrix consists of a vector of real values in variable pr and of imaginary values in pi. The example reads the matrix back into the C# program.

The reference to the MATLAB Type Library for C# is:

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

From your C# client program, add a reference to your project to the MATLAB COM object. For example, in Microsoft® Visual Studio®, open your project. From the Project menu, select Add Reference. Select the COM tab in the Add Reference dialog box. Select the MATLAB application. Refer to your vendor documentation for details.

Here is the complete example:

using System;
namespace ConsoleApplication4
class Class1
static void Main(string[] args)
MLApp.MLApp matlab = new MLApp.MLApp(); 

System.Array pr = new double[4];

System.Array pi = new double[4];

matlab.PutFullMatrix("a", "base", pr, pi);

System.Array prresult = new double[4];
System.Array piresult = new double[4];

matlab.GetFullMatrix("a", "base", ref prresult, ref piresult);

See Also