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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
object | Any | Yes | — | Scalar handle object that receives a per-instance dynamic property. |
property_name | PropertyName | Yes | — | Name of the dynamic property to add. |
Returns
| Name | Type | Description |
|---|---|---|
prop | Any | Dynamic property metadata handle. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:dynamicprops:InvalidTarget | The target is not a valid handle object. | dynamicprops: target must be a valid handle object |
RunMat:dynamicprops:InvalidName | The property name is empty or not a valid identifier. | dynamicprops: invalid property name |
RunMat:dynamicprops:DuplicateProperty | A class-defined or dynamic property already exists with the requested name. | dynamicprops: property already exists |
RunMat:dynamicprops:InvalidMetadata | A dynamic property metadata handle is invalid or malformed. | dynamicprops: invalid dynamic property metadata |
RunMat:dynamicprops:UnsupportedMetadataProperty | A metadata property assignment uses an unsupported property name or value. | dynamicprops: unsupported dynamic property metadata assignment |
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.
addpropdoes not accept an initial value. Numeric or integer data assigned later belongs to the dynamic property and follows ordinary object-property assignment semantics; it is not anaddpropinput or output.- The new property is immediately readable and writable through dot syntax,
getfield, andsetfield. - The returned metadata handle exposes
Name,DefiningClass,GetAccess,SetAccess,Dependent,Hidden,Transient,NonCopyable,AbortSet,SetObservable,GetObservable, andDescriptionfields. - Writable metadata fields update the target object's dynamic property metadata.
NameandDefiningClassare 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.gainExpected output:
value = 7Set metadata
p = addprop(s, 'label');
p.Hidden = true;
tf = p.HiddenExpected 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.
Related Introspection functions
assignin · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · evalc · feval · findprop · getcallinfo · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · keyboard · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · notify · onCleanup · stats · str2func · superclasses · underlyingType · verLessThan · version · which · who · whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how addprop is executed, line by line, in Rust.
- View the source for addprop 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.