isempty - Determine whether array is empty - MATLAB (original) (raw)

Determine whether array is empty

Syntax

Description

TF = isempty([A](#d126e910987)) 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.

example

Examples

collapse all

Empty Multidimensional Array

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)

Empty Arrays and Missing Values

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 = 1x2 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)

Empty String Arrays

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 = 1x3 string "" "" ""

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

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

Input Arguments

collapse all

A — Input array

scalar | vector | matrix | multidimensional array | table | timetable

Input array or table, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.

Tips

Extended Capabilities

Tall Arrays

Calculate with arrays that have more rows than fit in memory.

Theisempty function fully supports tall arrays. For more information, see Tall Arrays.

C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

HDL Code Generation

Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

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).

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 before R2006a