RunMat
GitHub

subsref — Dispatch object indexing requests to a class-specific Class.subsref implementation.

subsref(obj, kind, payload) is the advanced builtin that RunMat uses to implement overloaded indexing on objects and handle objects. Normal MATLAB syntax such as obj.field, obj(2), and obj{1} generally lowers to this mechanism automatically. The global builtin resolves the receiver's class name and forwards the request to Class.subsref.

How subsref works

  • The receiver must be an object or handle object.
  • The kind argument selects the indexing form: '.', '()', or '{}'.
  • For dot indexing, payload is typically a field/property name string.
  • For () and {} indexing, payload is typically a cell array of indices.
  • The builtin forwards the call to the receiver's class-specific Class.subsref implementation.
  • Prefer normal indexing syntax in user code; direct calls to subsref are mainly useful for advanced dispatch or testing.

How RunMat runs 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:00

Read a datetime property explicitly

t = datetime(2024, 4, 9);
fmt = subsref(t, ".", "Format")

Expected output:

fmt =
    'dd-MMM-yyyy HH:mm:ss'

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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how subsref works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat for free

Open the sandbox and start running MATLAB code in seconds. No account required.