主要内容

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

自定义对象索引

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

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

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

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

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

函数

builtin从已重载的方法执行内置函数
numArgumentsFromSubscript基于 subsref 和 subsasgn 的自定义索引的参量数目
matlab.indexing.isScalarClassDetermine whether input is scalar class (自 R2024b 起)
listLengthNumber of arguments returned from customized indexing operations
subsref使用函数调用的索引引用
subsasgn使用函数调用进行下标赋值
subsindex将对象转换为数组索引
substruct创建索引结构体参量

主题