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.

mustBeNonempty

Validate that value is nonempty or issue error

Syntax

mustBeNonempty(A)

Description

example

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

mustBeNonempty accepts user-defined objects if the class of the object implements this method:

Examples

collapse all

Use mustBeNonempty to validate that the input is not empty.

Create a containers.Map.

A = containers.Map;

Validate that A is not an empty value.

mustBeNonempty(A)
Error using mustBeNonempty (line 13)
Values must not be empty.

Creating a containers.Map with no input arguments results in an empty object.

This class constrains the value of Prop1 to nonempty values. The default value must also be nonempty.

classdef MyClass
   properties
      Prop1 {mustBeNonempty} = containers.Map(1,'First')
   end
end

Create an object and assign a value to its property.

obj = MyClass;
obj.Prop1 = containers.Map;
Error setting 'Prop1' property of 'MyClass' class:
Values must not be empty.

When you assign a value to the property, MATLAB® calls mustBeNonempty with the value being assigned to the property. mustBeNonempty issues an error because the value assigned to Prop1 is empty.

Input Arguments

collapse all

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

  • Any MATLAB data type

  • MATLAB classes that implement isempty.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration
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?