Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

自定义对象索引

为您的类自定义索引引用和赋值

自定义对象的索引引用和赋值行为。用户定义的类拥有与 MATLAB® 内置类相同的索引行为,但您可以通过从一个或多个超类继承来修改此行为。

您可以通过模块化索引 mixin 类(自 R2021b 开始提供)来单独自定义各索引操作。例如,您可以通过从 matlab.mixin.indexing.RedefinesParen 继承来自定义圆括号索引,同时对圆点和花括号索引使用默认 MATLAB 行为,而不编写额外的代码。

您也可以在类中重载 subsrefsubsasgn 函数,但这种方法要求您重载圆括号、圆点和花括号索引,即使您只需自定义一种行为也是如此。请尽可能使用模块化索引类。

matlab.mixin.indexing.RedefinesParenCustomize class indexing operations that use parentheses (自 R2021b 起)
matlab.mixin.indexing.RedefinesDotCustomize class indexing operations that use dots (自 R2021b 起)
matlab.mixin.indexing.RedefinesBraceCustomize class indexing operations that use braces (自 R2021b 起)
matlab.indexing.IndexingOperationType of customized indexing operation and referenced indices (自 R2021b 起)
matlab.mixin.ScalarEnforce scalar behavior for class instances (自 R2021b 起)
matlab.mixin.indexing.ForbidsPublicDotMethodCallDisallow calling public methods using dot notation (自 R2021b 起)
matlab.mixin.indexing.OverridesPublicDotMethodCall用圆点表示法调用公共方法会调用重载的点索引 (自 R2021b 起)

函数

全部展开

listLengthNumber of arguments returned from customized indexing operations (自 R2021b 起)
subsref下标引用
subsasgn重新定义下标赋值
subsindex将对象转换为数组索引
substructsubsasgnsubsref 创建结构体参数
builtin从已重载的方法执行内置函数
numArgumentsFromSubscript基于 subsref 和 subsasgn 的自定义索引的参数数目

主题