How do I create enumerated types in MATLAB?

前端 未结 10 2143
不知归路
不知归路 2020-12-02 17:04

Are there enumerated types in MATLAB? If not, what are the alternatives?

10条回答
  •  隐瞒了意图╮
    2020-12-02 17:35

    If you need the enumerated types just for passing to C# or .NET assembly, you can construct and pass the enums with MATLAB 2010:

    A = NET.addAssembly(MyName.dll)
    % suppose you have enum called "MyAlerts" in your assembly
    myvar = MyName.MyAlerts.('value_1');
    

    you can also check the official MathWorks answer at

    How do I use .NET enumerated values in MATLAB 7.8 (R2009a)?

    // the enum "MyAlerts" in c# will look something like this
    public enum MyAlerts
    {
        value_1 = 0,
        value_2 = 1,
        MyAlerts_Count = 2,
    }
    

提交回复
热议问题