Main Content

本页的翻译已过时。点击此处可查看最新英文版本。

枚举

表示单个类型的值的固定名称集

使用枚举表示一组固定的命名值,其中所有值的类型都相同。您可以从其他类(例如内置的数值类型)派生枚举类。然后,枚举成员会继承超类的算术和排序运算。

函数

enumeration类枚举成员和名称
isenum确定变量是否为枚举

meta.EnumeratedValue描述 MATLAB 类的枚举成员

主题

定义和使用枚举

Named Values

Associate values with predefined names using constant properties or enumeration classes.

定义枚举类

通过在 classdef 文件中创建枚举代码块来定义枚举类。

Refer to Enumerations

Refer to enumeration members using the class name and the member name.

枚举的运算

对枚举使用逻辑、集合关系和字符串比较等运算。

Enumeration Class Restrictions

Enumeration classes restrict certain aspects of their use and definition.

Mutable Handle vs. Immutable Value Enumeration Members

Use a handle enumeration to enumerate a set of objects whose state can change over time. Use a value enumeration to enumerate a set of abstract (and immutable) values.

Save and Load Enumerations

The type of enumeration class determines the information MATLAB® saves with the class.

Hide Enumeration Members

Hiding enumeration members enables you to replace enumeration names without creating incompatibilities.

专用枚举类

Enumerations Derived from Built-In Classes

Enumeration classes derived from built-in types inherit behaviors from these types.

Enumerations That Encapsulate Data

Define properties in an enumeration class to associate specific data with enumeration members.

Enumerations for Property Values

Use enumeration classes to restrict properties to a predefined set of values.

相关信息