- Sets the State property to the off enumeration member defined by the
matlab.lang.OnOffSwitchState class.
For information on how MATLAB selects default values, see “Default Values Per Size and
Class” on page 8-37.
Order of Validation
When a value is assigned to the property, including default values that are specified in the
class definition, MATLAB performs validation in this order:
- Class validation — This validation can cause conversion to a different class, such as
conversion of a char to string. Assignment to properties follows MATLAB coercion
rules for arrays. - Size validation — This validation can cause size conversion, such as scalar expansion
or conversion of a column vector to a row vector. Assignment to a property that
specifies a size validation behaves the same as assignment to any MATLAB array. For
information on indexed assignment, see “Array Indexing”. - Validator functions — MATLAB passes the result of the class and size validation to
each validation function, in left to right order. An error can occur before all validation
functions have been called, which ends the validation process. - Set method — MATLAB performs property validation before calling a property set
method, if one is defined for that property. Assignment to the property within a
property set or get method does not apply the validation again. Often, you can replace
property set methods using property validation.
Property Validation Errors
The ValueProp class uses size, class, and function validation to ensure that an
assignment to the Value property is a double scalar that is not negative.
classdef ValueProp
properties
Value(1,1) double {mustBeNonnegative} = 0
end
end
This statement attempts to assign a cell array to the property. This assignment violates
the class validation.
a.Value = {10,20};
Validate Property Values