isempty - Determine whether array is empty - MATLAB (original) (raw)
Main Content
Determine whether array is empty
Syntax
Description
TF = isempty([A](#d126e921195))
returns logical 1
(true
) if A
is empty, and logical 0
(false
) otherwise. An empty array, table, or timetable has at least one dimension with length 0, such as 0-by-0 or 0-by-5.
Examples
Create a 3-D array with one dimension length equal to zero, and determine if it is empty.
A = zeros(0,2,2); TF = isempty(A)
Compare empty arrays to arrays containing missing values.
In MATLAB®, an empty array has at least one dimension length equal to zero. An array containing missing values, such as NaN
or <undefined>
, is not necessarily empty.
Create a categorical vector with missing values.
cat1 = categorical([missing missing])
cat1 = 1×2 categorical
Since cat1
does not have a dimension of length zero, it is not empty.
Create a 0-by-0 categorical array and test if it is empty.
cat2 = categorical([]); TF2 = isempty(cat2)
Compare empty string arrays and strings with no characters.
Create a string vector whose elements are strings with no characters. str1
is nonempty since none of its dimensions have length zero.
str1 = 1×3 string "" "" ""
Create a 0-by-3 string array and test if it is empty.
str2 = strings(0,3); TF2 = isempty(str2)
Input Arguments
Input array or table, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.
Tips
- To determine whether a string array has empty strings (string elements with zero characters), use the == operator. For example, if
str
is a string containing zero characters, thenstr == ""
returns logical1
(true
). For more information on testing empty strings, see Test for Empty Strings and Missing Values. For information on string comparison, see Compare Text. - To test for missing values in an array, use the ismissing function.
Extended Capabilities
Theisempty
function fully supports tall arrays. For more information, see Tall Arrays.
The isempty
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 before R2006a