The findAttrValue function returns a cell array of property names that set the
specified attribute.
The findAttrValue function accesses information from metadata using these
techniques:
- If input argument, obj, is a char vector, use the meta.class.fromName static
method to get the meta.class object. - If input argument, obj, is an object, use the metaclass function to get the
meta.class object. - Every property has an associated meta.property object. Obtain these objects from
the meta.class PropertyList property. - Use the handle class findprop method to determine if the requested property
attribute is a valid attribute name. All property attributes are properties of the
meta.property object. The statement, findobj(mp,'PropertyName') determines
whether the meta.property object, mp, has a property called PropertyName. - Reference meta.property object properties using dynamic field names. For example,
if attrName = 'Constant', then MATLAB converts the expression mp.(attrName)
to mp.Constant - The optional third argument enables you to specify the value of attributes whose
values are not logical true or false (such as GetAccess and SetAccess).
function cl_out = findAttrValue(obj,attrName,varargin)
if ischar(obj)
mc = meta.class.fromName(obj);
elseif isobject(obj)
mc = metaclass(obj);
end
ii = 0; numb_props = length(mc.PropertyList);
cl_array = cell(1,numb_props);
for c = 1:numb_props
mp = mc.PropertyList(c);
if isempty (findprop(mp,attrName))
error('Not a valid attribute name')
end
attrValue = mp.(attrName);
if attrValue
if islogical(attrValue) || strcmp(varargin{1},attrValue)
ii = ii + 1;
cl_array(ii) = {mp.Name};
end
16 Information from Class Metadata