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

NameTypeRequiredDefaultDescription
aAnyYesSerialized object representation.

Returns

NameTypeDescription
bAnyDeserialized object.

Errors

IdentifierWhenMessage
RunMat:ObjectSerialization:InvalidArgumentThe input is not an object or serialized object envelope.object serialization: invalid argument
RunMat:ObjectSerialization:DispatchA saveobj or loadobj method cannot be resolved or executed.object serialization: method dispatch failed
RunMat:ObjectSerialization:RecursionLimitObject 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 save and 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 loadobj method 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:RecursionLimit for 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.

Open-source implementation

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

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.