loadobj — Restore an object payload produced during MAT-file loading.
loadobj(a) restores an object from a serialized object envelope. The load builtin calls this path automatically for objects saved by RunMat. When the saved class registers a static loadobj method, RunMat dispatches to it with the saved payload.
Syntax
b = loadobj(a)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
a | Any | Yes | — | Serialized object representation. |
Returns
| Name | Type | Description |
|---|---|---|
b | Any | Deserialized object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:ObjectSerialization:InvalidArgument | The input is not an object or serialized object envelope. | object serialization: invalid argument |
RunMat:ObjectSerialization:Dispatch | A saveobj or loadobj method cannot be resolved or executed. | object serialization: method dispatch failed |
RunMat:ObjectSerialization:RecursionLimit | Object serialization nesting exceeds the supported recursion limit. | object serialization: recursion limit exceeded |
How loadobj works
- The public signature is
b = loadobj(a). - RunMat recognizes object envelopes written by
saveand restores their payloads recursively. - If the saved class registers
Class.loadobj, that method receives the restored payload and its return value becomes the loaded variable. - If no registered
loadobjmethod exists and the payload is a scalar struct, RunMat reconstructs an object with the saved class name and payload fields as properties. - Plain non-envelope inputs pass through recursive struct/cell restoration unchanged.
- Recursion is bounded and reports
RunMat:ObjectSerialization:RecursionLimitfor cyclic or excessively nested payloads.
Does RunMat run loadobj on the GPU?
loadobj does not launch provider kernels.
Loaded object properties are CPU-resident after MAT-file loading.
GPU memory and residency
loadobj creates host values. Downstream acceleration may later promote numeric properties through the usual RunMat Accelerate paths.
Examples
Load an object from a MAT-file
save('object_state.mat', 'obj');
clear obj;
load('object_state.mat')Use class-specific static restoration
payload = saveobj(obj);
restored = classref('MyClass').loadobj(payload)Using loadobj with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how loadobj changes the result.
Run a small loadobj example, explain the result, then change one input and compare the output.
FAQ
Does load call loadobj automatically?⌄
Yes for object envelopes written by RunMat. load restores nested object payloads and calls registered static Class.loadobj methods when available.
What happens without a class-specific loadobj method?⌄
RunMat reconstructs a value object with the saved class name and property struct fields. If the saved payload was not a struct, the payload itself is returned.
Does this support arbitrary MATLAB object MAT-files?⌄
No. This support covers RunMat's own Level-5 object envelope and runtime object model. MATLAB v7.3/HDF5 class storage, object arrays, listener state, and handle alias preservation remain unsupported.
Related Oop functions
Serialization
Indexing
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how loadobj is executed, line by line, in Rust.
- View the source for loadobj 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.