Resetting individual properties to default values: 2018b
Show older comments
Hello all, I am trying to figure out how to reset class properties of the following form:
classdef myClass
properties
A (:,1) double = ones(10,1)
B (:,:) double
C (:,:) double
end
methods
function obj = partialReset(obj)
obj.B = [];
obj.A = setAsDefault;
end
end
end
Here, I am trying to reset some of my class properties, but not all. 3 cases above
(A) I want to reset A to its default value (whatever I set it as)
(B) I want to set B to its default empty value
(C) I want to leave C as is.
Now, I can see some workarounds:
function obj = partialReset(obj)
objTmp = myClass;
obj.A = objTmp.A;
obj.B = objTmp.B;
end
This returns an error, oddly enough: 'Size of value must match specified dimensions M×1 or be scalar', so while the empty property is valid on construction, it is not on assignment? Alternatively:
function objReset = partialReset(obj)
objReset = myClass;
objReset.C = obj.C;
end
I could do it this way, but this seems overly complicated if I am only resetting a few properties, and I have a lot that are being preserved. Note too that:
function obj = partialReset(obj)
obj.B = []
end
returns the error 'Size of value must match specified dimensions.
So, my question is whether there is a simple way to reset individual properties to their default values in Matlab 2018b.
-Cheers,
DP
Accepted Answer
More Answers (0)
Categories
Find more on Construct and Work with Object Arrays 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!