주요 콘텐츠

MathWorks.MATLAB.Types.MATLABObject

.NET class to represent scalar instances of MATLAB classes

Since R2022b

Description

Dynamic class to represent scalar instances of MATLAB® classes in .NET applications. Use this object to handle MATLAB classes that have no equivalent .NET type, such as MATLAB classdef types.

Class Details

Namespace:

MathWorks.MATLAB.Types
Superclass:System.Dynamic.DynamicObject

Methods

Public Methods

dynamic functionName(arg)

Call MATLAB functionName with supported argument list arg.

Member Variable

dynamic propNameGet or set an object property propName using the dot or period property specifier.

Examples

expand all

Create and resize a MATLAB Triangle object in C#. For information about creating this C# example, see ObjectExample.cs in Test Your .NET Development Environment.

Create a MATLAB class that defines a Triangle.

classdef Triangle < handle
    % Class used for .NET Engine examples.
    
    properties
        Base
        Height
    end
    properties (Dependent)
        Area
    end
    
    methods
        function obj = Triangle(base, height)
            % Construct an instance of this class.
            obj.Base = base;
            obj.Height = height;
        end
        
        function resize(obj, scale)
            %RESIZE Multiplies the Base and Height by SCALE.
            obj.Base = obj.Base * scale;
            obj.Height = obj.Height * scale;
        end

        function area = get.Area(obj)
            area = obj.Base * obj.Height / 2;
        end
    end
end

Create a triangle object.

double edgeLength = 1;
dynamic triangle = eng.Triangle(edgeLength, edgeLength);

Change the base and height of the triangle by setting the Base property to 3 and the Height property to 4.

triangle.Base = 3.0;
triangle.Height = 4.0;
double area = triangle.Area;

Resize the triangle by calling the resize method.

opts = new RunOptions() { Nargout = 0 };
triangle.resize(opts, 10.0);
area = triangle.Area;

Exceptions

MATLABExecutionException

Passing an invalid heterogeneous array to MATLAB.

Version History

Introduced in R2022b