- M corresponds to month
- m corresponds to minute
- s corresponds to second
- S corresponds to fractional second
dynamic property subclass use correct get and set methods
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
The superclass definition is -
classdef calibration ... % Class name
< dynamicprops %% Superclass
% dynamicprops makes handle class
% Creation Properties
properties (SetAccess = immutable)
created = datestr(now, 'yyyymmddTHHMMSS');
author = getenv('username');
end
% Properties
properties
name = '';
end
% Dynamic Property
properties (SetAccess = protected, Hidden = true)
metaDynProp = [];
end
methods
val = get(obj)
set(obj)
end
% Methods
methods
function addCal(obj,calName,calVal)
% ADDCAL adds calibration to a cal object
% Determine calibration type
if isscalar(calVal)
caseNum = 1;
elseif isstruct(calVal) && length(calVal) == 4
caseNum = 2;
elseif isstruct(calVal) && length(calVal) == 6
caseNum = 3;
else
error('Invalid Calibration')
end
% Create Calibration
obj.metaDynProp.(calName) = obj.addprop(calName);
%obj.metaDynProp.(calName).SetAccess = 'private';
switch(caseNum)
case 1 % Scalar case
% Assign Methods
obj.(calName) = scalar;
%obj.metaDynProp.(calName).SetMethod = 'set@scalar';
%obj.metaDynProp.(calName).GetMethod = @scalar.get;
case 2 % Table case
% Assign Methods
case 3 % Map case
% Assign Methods
end
% Set Property
set(obj.(calName),calVal);
end
end
end
The subclass definition is
classdef scalar < calibration
properties
value = [];
end
% Methods
methods
function set(obj,value)
obj.value = value;
end
function value = get(obj)
value = obj.value;
end
end
end
I would like to have the functionality where a calibration can be added such as
x = calibration;
x.addCal('a',1);
Then when x.a is called, the output is 1. However, with the above implementation the output is a scalar object. Also, is there a way to prevent properties from being inherited?
1 Kommentar
Seth Furman
am 24 Mai 2022
Note that, for datetime formats
so
created = datestr(now, "yyyymmddTHHMMSS");
as a datetime would be
created = datetime("now", Format="yyyyMMdd'T'HHmmss")
Antworten (1)
Ishan Gupta
am 27 Jul. 2022
You can set property as Private to avoid getting inherited.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Subclass Definition finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!