Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mustBeNonzero

Validate that value is nonzero or issue error

Syntax

mustBeNonzero(A)

Description

example

mustBeNonzero(A) issues an error if A is zero. This function does not return a value.

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

Examples

collapse all

Use mustBeNonzero to validate that the input does not contain values that are zero.

A is an array of numbers that is the result of a calculation:

A = sin([-1,0,1]);
msutBeNonzero(A)
Error using mustBeNonzero (line 14)
Value must not be zero.

This class constrains the value of Prop1 to be nonzero.

classdef MyClass
   properties
      Prop1 {mustBeNonzero}
   end
end

Create an object and assign a value to its property.

obj = MyClass;
obj.Prop1 = sin([-1,0,1]);
Error setting property 'Prop1' of class 'MyClass':
Value must not be zero.

When you assign a value to the property, MATLAB® calls mustBeNonzero with the value being assigned to the property. mustBeNonzero issues an error because the one of the values in A is zero.

Input Arguments

collapse all

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
Complex Number Support: Yes

Extended Capabilities

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

Introduced in R2017a

Was this topic helpful?