Say I have a MATLAB object defined in a class file
classdef foo
properties
bar
end
end
And I create a foo object
myfoo = foo();
Now I want to add another field to foo dynamically. What I want is
myfoo.newfield = 42;
but this will throw an error.
I know there is a way to dynamically add a field/property to a MATLAB object but I can't remember it or find it easily in the help. Anyone know the syntax?
Ok, found it. But it's not general, only subclasses of the dynamicprops class implement it. This is what I remember coming across. So I suspect the general answer to this question is you can't do it.
Any class that is a subclass of the dynamicprops class (which is itself a subclass of the handle class) can define dynamic properties using the addprop method. The syntax is:
P = addprop(H,'PropertyName')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With