Main Content

MathWorks.MATLAB.Types.MATLABProvider

.NET base class for invoking MATLAB functions

Since R2023b

Description

Dynamic class to represent instances of MathWorks.MATLAB.Engine.MATLABEngine or MathWorks.MATLAB.Runtime.MATLABRuntime (MATLAB Compiler SDK) classes in .NET applications. The MATLABProvider class enables data conversion between MATLAB and .NET.

The matlab.engine.typedinterface.generateCSharp function, called explicitly or implicitly, generates signatures for object MATLABProvider so that you can use the same source code to build either a .NET application or a deployed .NET application to call a MATLAB function.

Class Details

Namespace:

MathWorks.MATLAB.Types

Examples

Pass MATLABProvider to Position Constructor

Create .NET application code for this MATLAB® Position class.

classdef Position
    properties
        X (1,1) double {mustBeReal}
        Y (1,1) double {mustBeReal}
    end

    methods
        function P = show(P)
            arguments
                P (1,1) Position
            end

            fprintf('Position: (%d, %d)\n', P.X, P.Y);
        end
    end
end

Generate the C# wrapper file for the function.

matlab.engine.typedinterface.generateCSharp("PositionApp",Classes="Position")

 Position.cs

The input to the constructor is a MATLABProvider object.

public  Position(MATLABProvider _matlab)

Create a Position object in your .NET application.

MATLABEngine matlab = MATLABEngine.StartMATLAB();
Position p1 = new Position(matlab, 1, 1);

Create a Position object in your deployed .NET application.

MATLABRuntime runtime = MATLABRuntime.StartMATLAB();
Position p2 = new Position(runtime, 1, 2);

For information about building an application from a MATLAB class, see Create C# Code from Strongly Typed MATLAB Function.

Version History

Introduced in R2023b