isempty

Tests whether an array has no elements.

Category: Language Fundamentals > Matrices and Arrays

Syntax

tf = isempty(A)

True if any dimension of A is 0.

Description

isempty(A) is the same as numel(A) == 0. '', {} and zeros(0, 3) are empty, while a single space ' ', a zero and struct() are not. A common use is guarding the result of find or an optional argument: if isempty(idx).

Input arguments

A
Array of any type: numeric, text, cell, struct, table.

Output arguments

tf
Logical scalar.

Example

isempty([])
isempty(zeros(0, 3))
isempty('')
isempty(' ')
isempty(find([1 2 3] > 5))
Output
ans = logical
   1
ans = logical
   1
ans = logical
   1
ans = logical
   0
ans = logical
   1

See also

numel size ismissing isscalar