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 nonpositive or issue error





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

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


collapse all

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

A = 1 < 10;
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 constrains the value of Prop1 to a nonpositive values.

classdef MyClass
      Prop1 {mustBeNonpositive}

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.

Input Arguments

collapse all

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

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

Extended Capabilities

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

Introduced in R2017a