Main Content

Summary of MATLAB Compiler SDK .NET APIs

MATLAB® Compiler SDK™ provides two ways to deploy MATLAB functions within .NET applications written in C#. Each deployment option has a set of C# APIs that enable deployment. You can:

  • Deploy to .NET Applications using MATLAB Data API for .NET (since R2022b)

    • Application Interface: MATLAB Compiler SDK .NET API with two options:

      • Generic Interface (since R2022b)

      • Strongly Typed Interface (since R2023b)

    • Data Interface: MATLAB Data API for .NET (since R2022b)

  • Deploy to .NET Applications using MWArray API (since R2006a)

    • Application Interface: MATLAB Compiler SDK .NET API

    • Data Interface: MWArray API

Deploy to .NET Applications using MATLAB Data API for .NET

Generic Interface (since R2022b)

  • In this approach, MATLAB Compiler SDK generates a code archive (.ctf file) containing MATLAB functions that you can deploy within a C# application.

  • You use the MATLAB Compiler SDK API for .NET as an interface between the C# application and the code archive containing the deployed MATLAB code.

  • You use the MATLAB Data API to handle data exchange between the C# application and deployed MATLAB functions.

Strongly Typed Interface (since R2023b)

  • In this approach, MATLAB Compiler SDK generates three essential components. First, it creates a code archive (.ctf file), which encapsulates the MATLAB functions to be deployed. Second, it crafts corresponding C# wrapper files that establish a mapping between MATLAB and C# input and output data types, and allow MATLAB functions to be called as .NET methods. Lastly, it generates a .NET assembly that can be used in place of the C# wrapper files. You deploy these artifacts within a C# application.

  • The interface allows you to define a mapping between MATLAB and C# data types. To create this mapping, you can use an arguments block in a MATLAB function, or a combination of properties and arguments blocks in a MATLAB class. For instance, if your C# application employs a uint32 data type representing a real scalar value, you would define this in your MATLAB code as (1,1) uint32 {mustBeReal}.

  • MATLAB packages map to C# namespaces, MATLAB classes map to C# structs, and methods maintain their names and functions, eliminating the need for extra top-level functions.

  • Limitations

    In R2023b: MATLAB handle class , and functions varargin, and varargout are not supported.

Deploy to .NET Applications Using MWArray API

In this approach, MATLAB Compiler SDK generates two sets of artifacts for integration into a C# application. The first set consists of a C# wrapper file and a corresponding assembly file, both utilizing MWArray classes for arguments and return values. This configuration mirrors intrinsic MATLAB data structures.

Simultaneously, MATLAB Compiler SDK generates a second set of corresponding artifacts that use native .NET System.Object types for method parameters and returns. This variation provides a more .NET centric perspective of the MATLAB function, replacing MWArray with standard .NET Object instances. The choice of deployment between these two sets of artifacts depends on the specific integration needs and the level of familiarity with MATLAB among the developers.

The MWArray API began supporting .NET Core starting from the R2019b release, and extended this support to .NET 5.0 and higher versions from the R2022a release onwards.

Related Topics