Main Content

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.

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
      Prop (1,:) double {mustBeReal,mustBeGreaterThan(Prop,10)} = 200;

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 Size property

  • Get the class name from the Class property

  • Get a cell array of function handles for the validation functions from the ValidatorFunctions property.

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;
         dim{k} = ':';
dim{end+1} = mp.Validation.Class.Name;
dim{end+1} = mp.Validation.ValidatorFunctions;
dim =

  1×4 cell array

    {[1]}    {':'}    {'double'}    {1×2 cell}

See Also


Related Topics