主要内容

构造和使用对象数组

对象数组的构造和串联;异构数组

构造对象数组、从数组引用对象及其属性,以及设计支持异构(混合类)数组的构造的类层次结构。

函数

createArrayCreate array of specified class and value (自 R2024a 起)
empty创建指定类的空数组

matlab.mixin.Heterogeneous异构数组构造的超类

主题

构建和访问对象数组

串联数组

  • 串联方法
    您可以将对象串联成数组。例如,假设您有类 MyClass 的三个实例,obj1obj2obj3。您可以使用方括号来形成由这些对象构成的数组。水平串联会调用 horzcat
  • 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.