Metadata Interface to Property Validation - MATLAB & Simulink (original) (raw)

Main Content

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

Access the matlab.metadata.Validation object from the property'smatlab.metadata.Property object. Get the validation information from the matlab.metadata.Validation object properties. Collect this information into a cell array and display it.

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

Topics