subsasgn — Dispatch object assignment requests to a class-specific Class.subsasgn implementation.
subsasgn(obj, kind, payload, rhs) is the advanced builtin that RunMat uses to implement overloaded indexed assignment on objects and handle objects. Normal syntax such as obj.field = value, obj(2) = value, and obj{1} = value generally lowers to this mechanism automatically. The global builtin resolves the receiver's class name and forwards the assignment to Class.subsasgn.
How subsasgn works
- The receiver must be an object or handle object.
- The
kindargument selects the assignment form:'.','()', or'{}'. - For dot assignment,
payloadis typically a field/property name string. - For
()and{}assignment,payloadis typically a cell array of indices. - The builtin forwards the assignment to the receiver's class-specific
Class.subsasgnimplementation and returns the updated object value. - Prefer normal assignment syntax in user code; direct calls to
subsasgnare mainly useful for advanced dispatch or testing.
How RunMat runs subsasgn on the GPU
subsasgn performs no provider dispatch; it forwards assignment requests to the appropriate class-specific host implementation.
GPU memory and residency
subsasgn is host-side object dispatch and does not itself manage GPU residency.
Examples
Change a datetime display format explicitly
t = datetime(2024, 4, 9);
t = subsasgn(t, ".", "Format", "yyyy-MM-dd");
disp(t)Expected output:
2024-04-09Replace one element of a datetime array explicitly
t = datetime([2024 2025], [1 6], [15 20]);
t = subsasgn(t, "()", {2}, datetime(2030, 1, 1));
disp(t)Expected output:
15-Jan-2024 00:00:00
01-Jan-2030 00:00:00FAQ
Should I call subsasgn directly in normal code?
Usually no. Prefer ordinary assignment syntax like obj.field = value or obj(2) = value. 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 subsasgn actually do?
It resolves the receiver's class and forwards the assignment to that class's Class.subsasgn implementation.
Related Oop functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how subsasgn works, line by line, in Rust.
- View subsasgn.rs on GitHub
- Learn how the 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 — 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.