This example creates complex data in the 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.
Here is the complete example:
using System; namespace ConsoleApplication4 { class Class1 { [STAThread] static void Main(string[] args) { MLApp.MLApp matlab = new MLApp.MLApp(); System.Array pr = new double[4]; pr.SetValue(11,0); pr.SetValue(12,1); pr.SetValue(13,2); pr.SetValue(14,3); System.Array pi = new double[4]; pi.SetValue(1,0); pi.SetValue(2,1); pi.SetValue(3,2); pi.SetValue(4,3); 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); } } }