Hello all,
Yet another classdef question from me. Let us say I have a bunch of properties for some custom class, and that some are data properties that are numerical arrays, and some are metadata properties that are of mixed classes. It is useful to use the following:
classdef myClass properties % Metadata
name char author char date datetime end properties % Data
a (:,1) double b (:,1) double c (:,1) double d (:,1) double endend
Now, I may want to index into my data properties or, more likely, truncate a single object or concatenate two of them. Now, I clearly want to only trunc/cat the data properties, but for now I am stuck adding a method like the following:
function obj = trunc(obj,s,e) obj.a = obj.a(s:e); obj.b = obj.b(s:e); obj.c = obj.c(s:e); obj.d = obj.d(s:e);endfunction obj = cat(obj,obj2) obj.a = cat(1,obj.a,obj2.a) obj.b = cat(1,obj.b,obj2.b) obj.c = cat(1,obj.a,obj2.c) obj.d = cat(1,obj.b,obj2.d)end
Nominally I would have something like this pseudocode
function obj = trunc(obj,s,e) datProps = properties(obj,'block','Data') for ii = 1:length(datProps) obj.(datProps{ii}) = obj.(datProps{ii})(s:e) endend
and similarly for cat. Is there any way of doing this? It would be extremely useful for classes with a large number of properties.
Side note; I have a parallel concern with the results of doc myClass as it currently returns all of the properties but in an alphabetical/case sorted list. I can think of a number of ways to leverage both properties and methods blocks if both the comments, and a block label, could be attached, and/or if functions could apply only to properties within a set block.
After writing, this may be better for suggestions, but maybe someone has an idea for how to do this in 2019?
-DP
Best Answer