addprop — Add a per-instance dynamic property to a handle object.

prop = addprop(obj, name) adds a dynamic property to a valid dynamicprops handle object and returns a matlab.metadata.DynamicProperty metadata handle for that per-instance property.

Syntax

prop = addprop(object, property_name)

Inputs

NameTypeRequiredDefaultDescription
objectAnyYesScalar handle object that receives a per-instance dynamic property.
property_namePropertyNameYesName of the dynamic property to add.

Returns

NameTypeDescription
propAnyDynamic property metadata handle.

Errors

IdentifierWhenMessage
RunMat:dynamicprops:InvalidTargetThe target is not a valid handle object.dynamicprops: target must be a valid handle object
RunMat:dynamicprops:InvalidNameThe property name is empty or not a valid identifier.dynamicprops: invalid property name
RunMat:dynamicprops:DuplicatePropertyA class-defined or dynamic property already exists with the requested name.dynamicprops: property already exists

How addprop works

  • The target must be a valid handle object whose class inherits from dynamicprops; value objects, ordinary handle classes, and structs are rejected.
  • The property name must be a valid identifier and must not duplicate a class-defined property or an existing dynamic property on the same instance.
  • The new property is immediately readable and writable through dot syntax, getfield, and setfield.
  • The returned metadata handle exposes Name, DefiningClass, GetAccess, SetAccess, Dependent, Hidden, Transient, NonCopyable, AbortSet, SetObservable, GetObservable, and Description fields.
  • Writable metadata fields update the target object's dynamic property metadata. Name and DefiningClass are read-only.
  • delete(prop) removes the dynamic property and invalidates the metadata handle.

GPU memory and residency

addprop mutates host-side object metadata. GPU-resident numeric values assigned into dynamic properties follow the same residency behavior as ordinary object properties.

Examples

Add and use a dynamic property

classdef Sensor < dynamicprops
end
s = new_object('Sensor');
p = addprop(s, 'gain');
s.gain = 7;
value = s.gain

Expected output:

value = 7

Set metadata

p = addprop(s, 'label');
p.Hidden = true;
tf = p.Hidden

Expected output:

tf = logical(1)

Using addprop with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how addprop changes the result.

Run a small addprop example, explain the result, then change one input and compare the output.

FAQ

Does addprop work on value classes?

No. MATLAB dynamic properties are handle-object instance state, so RunMat requires a valid handle object.

Are dynamic properties saved to MAT files?

Not as full classdef metadata. RunMat saves object property values through the existing object serialization path, but complete dynamic-property persistence requires broader classdef persistence support.

Do SetObservable and GetObservable fire property listeners?

The metadata flags are stored and reported, but full observable-property listener semantics are not implemented yet.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how addprop 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.