Documentation

mustBeNonnegative

Validate that value is nonnegative or issue error

Syntax

mustBeNonnegative(A)

Description

example

mustBeNonnegative(A)issues an error ifAis negative. This function does not return a value.

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

Examples

collapse all

UsemustBeNonnegativeto validate that the input contains only nonnegative values.

Therandnfunction creates normally distributed random numbers.

A = randn(1,5);

Validate that the random numbers are nonnegative.

mustBeNonnegative(A)
Error using mustBeNonnegative (line 14) Value must be nonnegative.

This class constrains the value ofProp1to nonnegative values.

classdefMyClasspropertiesProp1 {mustBeNonnegative}endend

Create an object and assign a value to its property.

obj = MyClass; obj.Prop1 = -10;
Error using mustBeNonnegative (line 14) Value must be nonnegative.

When you assign a value to the property, MATLAB®callsmustBeNonnegativewith the value being assigned to the property.mustBeNonnegativeissues an error because the value-10is negative.

Input Arguments

collapse all

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

Example:A = 1does not generate an error.

Extended Capabilities

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

Introduced in R2017a

Was this topic helpful?