Main Content

isempty

Determine whether array is empty

Description

example

TF = isempty(A)returns logical1(true) ifAis empty, and logical0(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

collapse all

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)
TF =logical1

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 asNaNor, is not necessarily empty.

Create a categorical vector with missing values.

cat1 =categorical([missing missing])
cat1 =1x2 categorical 

Sincecat1does not have a dimension of length zero, it is not empty.

TF1 = isempty(cat1)
TF1 =logical0

Create a 0-by-0 categorical array and test if it is empty.

cat2 = categorical([]); TF2 = isempty(cat2)
TF2 =logical1

Compare empty string arrays and strings with no characters.

Create a string vector whose elements are strings with no characters.str1is nonempty since none of its dimensions have length zero.

str1 = strings(1,3)
str1 =1x3 string"" "" ""
TF1 = isempty(str1)
TF1 =logical0

Create a 0-by-3 string array and test if it is empty.

str2 = strings(0,3); TF2 = isempty(str2)
TF2 =logical1

Input Arguments

collapse all

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, ifstris a string containing zero characters, thenstr == ""returns logical1(true). For more information on testing empty strings, see测试空字符串和缺失值. For information on string comparison, seeCompare Text.

  • To test for missing values in an array, use theismissingfunction.

Extended Capabilities

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

HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

H版istory

Introduced before R2006a

See Also

|