Main Content

mustBeGreaterThanOrEqual

Validate that value is greater than or equal to another value

Description

example

mustBeGreaterThanOrEqual(value,c)throws an error if any elements invalueare less than the scalarc。这个函数并不return a value.

mustBeGreaterThanOrEqualcalls these functions to determine ifvalueis greater than or equal toc:

Class support: All numeric classes,logical, and MATLAB®classes that overload the functions called bymustBeGreaterThanOrEqual

This function ignores empty values in the first input argument. Therefore, no error is thrown when the property or function argument value is empty.

Examples

collapse all

UsemustBeGreaterThanOrEqualto validate that the values in the array are greater than or equal to3

mustBeGreaterThanOrEqual([2,3,4],3)
Error using mustBeGreaterThanOrEqual (line 19) Value must be greater than or equal to 3.

Restrict property values to be greater than or equal to a specified value.

This class constrains the value ofProp1to be greater than or equal to3

classdefMyClasspropertiesProp1{mustBeGreaterThanOrEqual(Prop1,3)}endend

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 greater than or equal to 3.

当你分配一个值的属性,MATLAB callsmustBeGreaterThanOrEqualwith the value being assigned to the property.mustBeGreaterThanOrEqualissues an error because the value2is not greater than or equal to3

This function restricts the input argument to be values that are greater than or equal to 5.

functionr = mbGreaterThanOrEqual(x)argumentsx{mustBeGreaterThanOrEqual(x,5)}endr = x - 5;end

Calling the function with a vector that contains values that are less than 5 does not meet the requirements defined withmustBeGreaterThanOrEqualand results in an error.

x = [12.7, 45.4, 4.9, 77.1, 53.1]; r = mbGreaterThanOrEqual(x);
Error using mbGreaterThanOrEqual Invalid input argument at position 1. Value must be greater than or equal to 5.

Input Arguments

collapse all

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

Constant value that thevalueargument must be greater than or equal to, specified as a scalar of one of the following:

Tips

  • mustBeGreaterThanOrEqualis designed to be used for property and function argument validation.

Extended Capabilities

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

Introduced in R2017a