メインコンテンツ

MathWorks.MATLAB.Types.MATLABProvider

R2026b

MATLAB 関数を呼び出すための .NET 基底クラス

R2023b 以降

説明

.NET アプリケーションで MathWorks.MATLAB.Engine.MATLABEngine クラスまたは MathWorks.MATLAB.Runtime.MATLABRuntime (MATLAB Compiler SDK) クラスのインスタンスを表す動的クラス。MATLABProvider クラスは、MATLAB と .NET の間のデータ変換を可能にします。

matlab.engine.typedinterface.generateCSharp 関数は、明示的または暗黙的に呼び出され、オブジェクト MATLABProvider のシグネチャを生成します。これにより、同じソース コードを使用して .NET アプリケーションまたは展開済み .NET アプリケーションをビルドし、MATLAB 関数を呼び出すことができます。

クラスの詳細

名前空間:

MathWorks.MATLAB.Types

例

Position コンストラクターに MATLABProvider を渡す

次の MATLAB® Position クラス用の .NET アプリケーション コードを作成します。

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

関数用の C# ラッパー ファイルを生成します。

matlab.engine.typedinterface.generateCSharp("PositionApp",Classes="Position")
/* File: Position.cs
*
* MATLAB Strongly Typed Interface Version: R2023b
* C# source code generated on: 08-Jun-2023
*/
using System;
using MathWorks.MATLAB.Types;
using MathWorks.MATLAB.Exceptions;

public  struct Position { 
    private void ThrowIfDefaultValue()
    {
        if (_matlab == null || _objrep == null)
        {
            throw new UnsupportedTypeException("Position object is not initialized.");
        }
    }
    private dynamic _objrep;
    private dynamic _matlab;
    public  Position(MATLABProvider _matlab){
        this._matlab = _matlab;
        _objrep = (MATLABArray)this._matlab.Position(new RunOptions(nargout:1));
    }
    public double X {
        get => _matlab.matlab.@internal.engine.getProperty(_objrep, "X");
        set => _objrep = _matlab.matlab.@internal.engine.setProperty(_objrep,"X",value);
    }
    public double Y {
        get => _matlab.matlab.@internal.engine.getProperty(_objrep, "Y");
        set => _objrep = _matlab.matlab.@internal.engine.setProperty(_objrep,"Y",value);
    }
    public void show(){
        _objrep.show(new RunOptions(nargout:0));
    }
    public void show( out dynamic _P){
        _P = (MATLABArray)_objrep.show(new RunOptions(nargout:1));
    }
    public static implicit operator MATLABObject(Position position){
        position.ThrowIfDefaultValue();
        return position._objrep;
    }
    public static implicit operator Position(MATLABObject _obj){
        Position position = default;
        position._objrep = _obj;
        position._matlab = typeof(MATLABObject).GetField("Matlab", 
            System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(_obj);
        return position;
    }
}

コンストラクターへの入力は MATLABProvider オブジェクトです。

public  Position(MATLABProvider _matlab)

.NET アプリケーションで Position オブジェクトを作成します。

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

展開済み .NET アプリケーションで Position オブジェクトを作成します。

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

MATLAB クラスからのアプリケーションのビルドの詳細については、厳密に型指定された MATLAB 関数からの C# コードの作成を参照してください。

バージョン履歴

R2023b で導入