OOP/Class Questions: deepcopy & AbortSet

2 views (last 30 days)
1. What is the correct way to deepcopy an instance of a class/object whose superclass is type `handle`? `copyobj` doesn't seem to work for a handle-derived class that isn't strictly a graphics object, and overloading `copyobj` as a class method to copy each field into a new instance and return a handle seems to take just as long as constructing a new object.
2. Does it make sense to specify `AbortSet` for a `Dependent` class property? Yes, I understand you can't `set` a `Dependent` property but I have defined an overloaded `set` method to access a private class property that can be set. Does it make most sense to only specify `AbortSet` for the private class property it accesses? i.e.
properties(Dependent, AbortSet)
%display settings
properties(Access = private, AbortSet)
privateFilterTimeBand = 30;
function propval = get.filterTimeBand(hObj)
%return the number of points used in the 2D DTS filter time
%band (x-direction / columns)
propval = hObj.privateFilterTimeBand;
function set.filterTimeBand(hObj,nCol)
%update the number of points used in the 2D DTS filter time
%band (x-direction / columns)
if isnumeric(nCol) && nCol>0
%first update the filter time band
hObj.privateFilterTimeBand = ceil(nCol);
%next re-filter temperature using the new filter window

Accepted Answer

Guillaume on 3 Apr 2018
1. Deriving from matlab.mixin.copyable is the easiest. It's a bit of work to implement but it provides a well defined interface.
2. AbortSet on a dependent property is pointless since it'll never have a PreSet or PostSet event nor will it ever be set. I would assume that matlab just ignore the attribute for dependent properties but just in case, I would not include it.

More Answers (0)


Find more on Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!