Main Content

mustBeGreaterThan

Validate that value is greater than another value

Description

example

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

mustBeGreaterThancalls these functions to determine ifvalueis greater thanc:

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

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

UsemustBeGreaterThanto validate that the values in the first input are greater than the value of the second input.

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

This class restricts the value ofProp1to be greater than2

classdefMyClasspropertiesProp1{mustBeGreaterThan(Prop1,2)}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 2.

When you assign a value to the property, MATLAB callsmustBeGreaterThanwith the value being assigned to the property.mustBeGreaterThanissues an error because the value2is not greater than2

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

functionr = mbGreaterThan(x)argumentsx{mustBeGreaterThan(x,5)}endr = x - 5;end

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

x = [12.7, 45.4, 5.0, 77.1, 53.1]; r = mbGreaterThan(x);
Error using mbGreaterThan Invalid input argument at position 1. Value must be greater than 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, specified as a scalar of one of the following:

Tips

  • mustBeGreaterThanis 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