mustBeNonempty - Validate that value is nonempty - MATLAB (original) (raw)
Main Content
Validate that value is nonempty
Syntax
Description
mustBeNonempty([value](#bviy%5Fyo-A))
throws an error if value
is empty. This function does not return a value.
mustBeNonempty
calls the following function to determine if the input is nonempty:
Class support: All MATLABĀ® classes
Examples
Use mustBeNonempty
to validate that the input is not empty.
Create a containers.Map.
Validate that A
is not an empty value.
Creating a containers.Map
with no input arguments results in an empty object.
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.
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
.
Error using mbNonempty (line 3) mbNonempty('') ^^ Invalid argument at position 1. Value must not be empty.
Input Arguments
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
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).
Version History
Introduced in R2017a