How do I remove a dynamic property from a class?

조회 수: 20 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2018년 4월 23일
답변: MathWorks Support Team 2018년 4월 23일
I have a class "A" that has a property called "Sigs" of class "B". Class "B" inherits from "dynamicprops" and the constructor for "A" populates "Sigs" with a bunch of dynamic properties that are of class "C". I want to be able to delete those properties from "Sigs". How do I do that?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2018년 4월 23일
In order to remove a dynamic property, save the "meta.DynamicProperty" object that is returned by "addprop" and then use the "delete" function of that object.
In order to save the "meta.DynamicProperty" objects, create a struct "sig_meta" that maps from the property name to the "meta.DynamicProperty" object. This was a property of the "A" class.
If you want to hide the "sig_meta" from the property list of your "A" class, use "Hidden=true". This allows you to still use the property, but it will not clutter your Command Window outputs.
Finally, in order to delete the dynamic property, use "delete" on the field of the struct "sig_meta" in your "A" class. Then, call "rmfield" to keep the struct and the "B" class properties in sync.
An example is attached.
To play with this example, execute
>> obj = A;
>> obj.Sigs
>> obj.sig_meta
>> delete(obj.sig_meta.prop10);
>> obj.Sigs
>> obj.sig_meta
>> obj.sig_meta = rmfield(obj.sig_meta,'prop10')
>> obj.sig_meta;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by