Main Content

isempty

Determine whether array is empty

Description

example

TF = isempty(A)returns logical1(真的) ifA是空的,逻辑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

collapse all

创建一个3-D数组,其一个维度长度等于零,并确定它是否为空。

A = zeros(0,2,2); TF = isempty(A)
TF =logical1

将空数组与包含缺失值的数组进行比较。

In MATLAB®, an empty array has at least one dimension length equal to zero. An array containing missing values, such asNaN或者, is not necessarily empty.

Create a categorical vector with missing values.

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

自从cat1does 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.str1是非空的,因为其尺寸均无长度为零。

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 =字符串(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(真的). For more information on testing empty strings, see测试空字符串和缺失值。有关字符串比较的信息,请参阅Compare Text

  • 要在数组中测试缺少值,请使用ismissingfunction.

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

|