mustBeNonempty
Validate that value is nonempty
Syntax
Description
Examples
Validate Input Not Empty
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)
Value must not be empty.
Creating a containers.Map
with no input arguments results in an empty object.
Restrict Property Values
This class restricts 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. Value 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.
Restrict Function Argument Values
This function restricts the input argument to be a nonempty character vector.
function str = mbNonempty(name) arguments name (1,:) char {mustBeNonempty} end str = sprintf('Name: %s',name); end
Calling this function with an empty character vector results in an error being thrown by mustBeNonempty
.
mbNonempty('')
Error using mbNonempty (line 3) mbNonempty('') ^^ Invalid argument at position 1. Value must not be empty.
Input Arguments
value
— Value to validate
scalar | array
Value to validate, specified as a scalar or array of any MATLAB type or class
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
Tips
mustBeNonempty
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™.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The mustBeNonempty
function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray
(Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2017a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)