This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Validate that value is less than another value or issue error





mustBeLessThan(A,B) issues an error if any elements in A are not less than the scalar B. This function does not return a value.

mustBeLessThan accepts user-defined objects if the class of the object implements these methods:

This function ignores empty values in the property input argument. Empty property values do not cause an error.


collapse all

Use mustBeLessThan to validate that the values in the first input are less than the value of the second input.

mustBeLessThan([2 3 4],2)
Error using mustBeLessThan (line 19)
Value must be less than 2.

Constrain property values to be less than a specified value.

This class constrains the value of Prop1 to be less than 2.

classdef MyClass
      Prop1 {mustBeLessThan(Prop1,2)}

Create an object and assign a value to its property.

obj = MyClass;
obj.Prop1 = 2;
Error setting property 'Prop1' of class 'MyClass':
Value must be less than 2.

When you assign a value to the property, MATLAB® calls mustBeLessThan with the value being assigned to the property. mustBeLessThan issues an error because the value 2 is not less than 2.

Input Arguments

collapse all

Value to validate, specified as a scalar or an array of one of the following:

When using mustBeLessThan as a property validator, this argument must be the property name, specified without quotation marks.

Value that A must be less than, specified as a scalar of one of the following:

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2017a