Metadata Interface to Property Validation
For information on property validation, see Validate Property Values.
You can determine what validation applies to a property by accessing the validation
metadata. Instances of the matlab.metadata.Validation class provide the following information about
property validation.
Class requirement of the property specified as a
matlab.metadata.ClassobjectSize requirements of the property value specified as an array of
matlab.metadata.FixedDimensionandmatlab.metadata.UnrestrictedDimensionobjectsFunction handles referencing validation functions applied to property values specified as a cell array of function handles.
For example, the ValidationExample class defines a property that must be an array of doubles that is 1-by-any number of elements and must be a real number that is greater than 10.
classdef ValidationExample properties Prop (1,:) double {mustBeReal,mustBeGreaterThan(Prop,10)} = 200; end end
Access the matlab.metadata.Validation object from the property's
matlab.metadata.Property object. Get the
validation information from the matlab.metadata.Validation object
properties. Collect this information into a cell array and display it.
Get the size information from the
SizepropertyGet the class name from the
ClasspropertyGet a cell array of function handles for the validation functions from the
ValidatorFunctionsproperty.
mc = ?ValidationExample; mp = findobj(mc.PropertyList,'Name','Prop'); sz = mp.Validation.Size; len = length(sz); dim = cell(1:len); for k = 1:len if isa(sz(k),'matlab.metadata.FixedDimension') dim{k} = sz(k).Length; else dim{k} = ':'; end end dim{end+1} = mp.Validation.Class.Name; dim{end+1} = mp.Validation.ValidatorFunctions; dim
dim =
1×4 cell array
{[1]} {':'} {'double'} {1×2 cell}See Also
matlab.metadata.Property | matlab.metadata.Validation