Personalizzazione dell’indicizzazione degli oggetti
Personalizzare il comportamento del riferimento indicizzato e dell’assegnazione per gli oggetti. Le classi definite dall'utente possiedono lo stesso comportamento di indicizzazione delle classi incorporate di MATLAB®. Tuttavia, è possibile modificare questo comportamento tramite l’ereditarietà da una o più superclassi.
Le classi mixin di indicizzazione modulare consentono di personalizzare le operazioni di indicizzazione individualmente. Ad esempio, è possibile personalizzare l'indicizzazione delle parentesi tramite l’ereditarietà da matlab.mixin.indexing.RedefinesParen
, mentre si utilizza il comportamento predefinito di MATLAB per l'indicizzazione dei punti e delle parentesi graffe senza scrivere codice supplementare.
È inoltre possibile sovraccaricare le funzioni subsref
e subsasgn
nelle classi, ma questa tecnica richiede che venga sovraccaricata l’indicizzazione di parentesi, punti e parentesi graffe anche se si deve personalizzare un solo comportamento. Quando è possibile, l'utilizzo delle classi di indicizzazione modulari è la procedura consigliata.
Classi
matlab.mixin.indexing.RedefinesParen | Customize class indexing operations that use parentheses (Da R2021b) |
matlab.mixin.indexing.RedefinesDot | Customize class indexing operations that use dots (Da R2021b) |
matlab.mixin.indexing.RedefinesBrace | Customize class indexing operations that use braces (Da R2021b) |
matlab.indexing.IndexingOperation | Type of customized indexing operation and referenced indices (Da R2021b) |
matlab.mixin.Scalar | Enforce scalar behavior for class instances (Da R2021b) |
matlab.mixin.indexing.ForbidsPublicDotMethodCall | Disallow calling public methods using dot notation (Da R2021b) |
matlab.mixin.indexing.OverridesPublicDotMethodCall | Calling public methods with dot notation invokes overloaded dot indexing (Da R2021b) |
Funzioni
builtin | Execute built-in function from overloaded method |
numArgumentsFromSubscript | Number of arguments from indexing methods |
matlab.indexing.isScalarClass | Determine whether input is scalar class (Da R2024b) |
listLength | Number of arguments returned from customized indexing operations (Da R2021b) |
subsref | Indexed reference using function call |
subsasgn | Subscripted assignment using function call |
subsindex | Convert object to array index |
substruct | Create indexing structure argument |
Argomenti
- Customize Object Indexing
MATLAB classes support object array indexing by default.
- Customize Parentheses Indexing for Mapping Class
This example shows how to customize parentheses indexing for a mapping class.
- Forward Indexing Operations
Forward additional levels of indexing after customized indexing operations.
- Overload end for Classes
Overload
end
for customized indexing applications. - Objects in Index Expressions
You can design objects that can be used as indices in indexing expressions.
- Code Patterns for subsref and subsasgn Methods
There are code patterns useful for modifying object indexing.