Main Content

mustBeNonpositive

Validate that value is nonpositive

Description

example

mustBeNonpositive(value) throws an error if value is positive. Values are positive when they are greater than zero. This function does not return a value.

mustBeNonpositive calls these functions to determine if the input is not positive:

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

Examples

collapse all

Use mustBeNonpositive to validate that the input contains only nonpositive values.

A = 1 < 10;
mustBeNonpositive(A)
Error using mustBeNonpositive (line 14)
Value must not be positive.

Because the expression 1 < 10 returns logical 1, the value of A is positive and causes mustBeNonpositive to issue an error.

This class restricts the value of Prop1 to a nonpositive values.

classdef MyClass
   properties
      Prop1 {mustBeNonpositive}
   end
end

Create an object and assign a value to its property.

obj = MyClass;
obj.Prop1 = 10;
Error setting property 'Prop1' of class 'MyClass':
Value must not be positive.

When you assign a value to the property, MATLAB calls mustBeNonpositive with the value being assigned to the property. mustBeNonpositive issues an error because the value 10 is positive.

This function declares two input arguments. Input lower must not be positive and input upper must be positive.

function r = mbNonpositive(lower,upper)
    arguments
        lower {mustBeNonpositive}
        upper {mustBePositive}
    end
    x = lower*pi:upper*pi;
    r = sin(x);
end

Calling the function with a value for lower that does not meet the requirements of mustBeNonpositive results an error.

r = mbNonpositive(2,4);
Error using mbNonpositive
Invalid input argument at position 1. Value must not be positive.

Input Arguments

collapse all

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

Example: value = -1 does not generate an error.

Tips

  • mustBeNonpositive is 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