构造和使用对象数组
对象数组的构造和串联;异构数组
构造对象数组、从数组引用对象及其属性,以及设计支持异构(混合类)数组的构造的类层次结构。
函数
createArray | Create array of specified class and value (自 R2024a 起) |
empty | 创建指定类的空数组 |
类
matlab.mixin.Heterogeneous | 异构数组构造的超类 |
主题
构建和访问对象数组
- 创建和初始化对象数组
可以使用几种不同的方法来构建对象数组。 - Accessing Properties and Methods in Object Arrays
You can access properties and invoke methods of object arrays as a whole or work with individual elements of the array. - Determine Array Class
You can determine the class of an array.
串联数组
- Concatenation Methods
You can concatenate objects into arrays. - Concatenating Objects of Different Classes
MATLAB® follows specific rules when you attempt to create an array with objects of different classes.
类转换
- Implicit Class Conversion
MATLAB can implicitly convert objects to a different class for concatenation, subscripted assignment, property validation, and argument validation. - Object Converters
You can convert an object of one class to an object of another class.
异构数组
- Designing Heterogeneous Class Hierarchies
Heterogeneous arrays can contain objects of different class, but all objects in the array must derive from a common superclass. - Heterogeneous Array Constructors
The class of a heterogeneous object array can change as you add array elements of different classes. You must ensure that constructors return objects that are the same class as the class defining the constructor.