isempty — Determine whether an array contains zero elements.
isempty classifies a value from its MATLAB-visible dimensions and returns one host logical scalar.
Syntax
tf = isempty(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Value whose MATLAB-visible dimensions are inspected.
Returns
tf- Type
LogicalArray- Description
- Logical scalar that is true when the input contains zero elements.
Errors
RunMat:isempty:InternalError- When
- Value or distributed shape metadata is invalid.
- Message
isempty: invalid shape metadata
RunMat:isempty:TooManyOutputs- When
- More than one output is requested.
- Message
isempty: too many output arguments
Element count
isempty(A) returns one logical scalar and is true when any visible dimension is zero. It checks the container shape and does not inspect cell contents or stored sparse values.
Numeric, logical, character, string, cell, struct, object, sparse, and complex arrays use their MATLAB-visible dimensions. Ordinary scalar values and function handles occupy one element and return false.
Text and empty containers
An empty character array has zero character elements and returns true. A string scalar is a 1-by-1 container even when its text is empty, so isempty("") is false. A zero-sized string array returns true.
A scalar struct or object is not empty; a zero-sized struct or object array is empty. Cell arrays are classified from their outer dimensions, regardless of the values stored in their cells.
Resident and distributed values
gpuArray and distributed inputs are classified from validated shape metadata without launching a kernel, allocating device memory, or reading payload data. The result is always a host logical scalar and forms a fusion boundary.
Examples
Check an empty numeric matrix
A = zeros(0, 3);
tf = isempty(A)Expected output:
tf = trueCheck an empty cell array
C = cell(0, 4);
tf = isempty(C)Expected output:
tf = trueDistinguish character and string containers
tf_chars = isempty('');
tf_string = isempty("")Expected output:
tf_chars = true and tf_string = falseCheck a scalar
tf = isempty(42)Expected output:
tf = falseCheck an empty string array
S = strings(0, 2);
tf = isempty(S)Expected output:
tf = trueInspect a resident empty shape
G = gpuArray(zeros(5, 0));
tf = isempty(G)Expected output:
tf = trueUsing isempty with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isempty changes the result.
Run a small isempty example, explain the result, then change one input and compare the output.
FAQ
Does isempty gather gpuArray data?⌄
No. A gpuArray handle always carries its shape, so the predicate reads metadata only.
Why is isempty("") false but isempty('') true?⌄
The string value is a 1-by-1 string container; the character literal contains zero character elements.
Does isempty look inside cells?⌄
No. It checks only the cell array's outer dimensions.
How are structs and objects handled?⌄
Their array dimensions determine the result. Scalar instances are not empty; zero-sized arrays are empty.
Related Array functions
Introspection
height · iscolumn · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size · width
Accumulation
Sorting Sets
argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique
Shape
blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat
Creation
colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · meshgrid · nan · ndgrid · nonzeros · ones · peaks · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros
Combinatorics
Binning
Grouping
Source you can read
Every RunMat function's source is public. Read exactly how isempty is executed, line by line, in Rust.
- View the source for isempty in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.