Main Content

Pass Complex Data to MATLAB from C# Client

To pass data to MATLAB® from a C# application in MATLAB R2022b or later, consider using the MATLAB Engine API for .NET. For more information, see Pass .NET Data Types to MATLAB Functions and Execute MATLAB Functions from .NET.

If you need to maintain existing programs created for MATLAB R2022a or earlier using MATLAB as a COM Automation server, use this example which 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:

 C# Program

See Also


Related Topics