subsref — Dispatch overloaded object indexing operations to class-specific Class.subsref implementations.
subsref(obj, kind, payload) is the internal dispatch builtin for overloaded object indexing. MATLAB-style field, paren, and brace indexing lowers to this mechanism, which resolves class-specific Class.subsref handlers.
Syntax
out = subsref(obj, kind, payload)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
obj | Any | Yes | — | Object receiver. |
kind | StringScalar | Yes | — | Indexing kind token ('()', '{}', '.'). |
payload | Any | Yes | — | Indexing payload. |
Returns
| Name | Type | Description |
|---|---|---|
out | Any | Indexed value. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:InvalidObjectDispatch | Receiver is not an object or handle object. | subsref: requires object receiver |
RunMat:MissingSubsref | Target class does not implement subsref. | subsref: class does not define subsref for indexing operation |
How subsref works
- The receiver must be an object or handle object.
- The
kindargument selects the indexing form:'.','()', or'{}'. - For dot indexing,
payloadis typically a field/property name string. - For
()and{}indexing,payloadis typically a cell array of indices. - The builtin forwards the call to the receiver's class-specific
Class.subsrefimplementation. - Prefer normal indexing syntax in user code; direct calls to
subsrefare mainly useful for advanced dispatch or testing.
Does RunMat run subsref on the GPU?
subsref performs no provider dispatch; it forwards indexing requests to the appropriate class-specific host implementation.
GPU memory and residency
subsref is host-side object dispatch and does not itself manage GPU residency.
Examples
Index a datetime array explicitly
t = datetime([2024 2025], [1 6], [15 20]);
item = subsref(t, "()", {2})Expected output:
item =
20-Jun-2025 00:00:00Read a datetime property explicitly
t = datetime(2024, 4, 9);
fmt = subsref(t, ".", "Format")Expected output:
fmt =
'dd-MMM-yyyy HH:mm:ss'Using subsref with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how subsref changes the result.
Run a small subsref example, explain the result, then change one input and compare the output.
FAQ
Should I call subsref directly in normal code?⌄
Usually no. Prefer ordinary syntax like obj.field or obj(2). Direct calls are mainly for advanced dispatch and testing.
What values can kind take?⌄
RunMat's object-dispatch path expects '.', '()', or '{}'.
What does the global subsref actually do?⌄
It resolves the receiver's class and forwards the operation to that class's Class.subsref implementation.
Related Oop functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how subsref is executed, line by line, in Rust.
- View the source for subsref in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.