isempty — Test whether arrays are empty in MATLAB and RunMat.

isempty(A) returns true when A contains zero elements. Type coverage and shape handling follow MATLAB semantics.

Syntax

tf = isempty(A)

Inputs

NameTypeRequiredDefaultDescription
AAnyYesInput value to inspect.

Returns

NameTypeDescription
tfLogicalArrayTrue when input has zero elements.

How isempty works

  • Arrays are empty when any dimension is zero (prod(size(A)) == 0).
  • Character arrays report empty when either dimension is zero. String scalars are never empty ("" is a 1×1 string array whose content may be empty, but it still counts as one element).
  • Cell arrays, struct arrays, and tables (future work) follow their MATLAB dimensions; cell(0, n) is empty, while cell(1, 1) is not.
  • Scalars, logical values, numeric scalars, function handles, objects, and handle objects always return false because they occupy one element.
  • GPU tensors rely on device-provided shape metadata to avoid unnecessary transfers. If metadata is missing, RunMat gathers once to confirm the shape.

Does RunMat run isempty on the GPU?

isempty does not launch GPU kernels. For GPU-resident tensors (gpuArray values), RunMat inspects the shape stored in the GpuTensorHandle. When the active provider omits that metadata, the runtime downloads the tensor once to maintain MATLAB-compatible results. The builtin always returns a host logical scalar and does not allocate device memory, so it is safe in fused GPU expressions.

Examples

Checking if a matrix has any elements

A = zeros(0, 3);
tf = isempty(A)

Expected output:

tf = logical(1)

Detecting an empty cell array

C = cell(0, 4);
tf = isempty(C)

Expected output:

tf = logical(1)

Using isempty on a GPU-resident tensor

G = gpuArray(zeros(5, 0));
tf = isempty(G)

Expected output:

tf = logical(1)

Distinguishing char arrays from string scalars

chars = '';
tf_chars = isempty(chars);
str = "";
tf_str = isempty(str)

Expected output:

tf_chars = logical(1)
tf_str = logical(0)

Confirming that scalars are never empty

value = 42;
tf = isempty(value)

Expected output:

tf = logical(0)

Inspecting empty string arrays

S = strings(0, 2);
tf = isempty(S)

Expected output:

tf = logical(1)

Using 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 GPU data?

Only when the provider fails to populate shape metadata on the GPU handle. Otherwise, it answers using the metadata and avoids transfers.

Why is isempty("") false but isempty('') true?

String scalars are 1×1 arrays that hold text content, so they are not empty even when the text has length zero. Character arrays store individual characters; the empty char literal '' has zero columns, so it is empty.

How does isempty treat structs and objects?

Structs follow their array dimensions. A scalar struct (1×1) is not empty, while a 0×0 struct array is empty. Value objects and handle objects are always treated as scalar values, so isempty returns false.

Can isempty be used inside GPU-fused expressions?

Yes. The builtin returns a host logical scalar and does not allocate GPU buffers, so fusion plans remain valid.

Does isempty look inside cell arrays?

No. It only checks the container dimensions. To look at the contents, inspect individual cells.

What does isempty return for logical or numeric scalars?

They behave like any other scalar and return false.

Introspection

ismatrix · isscalar · isvector · length · ndims · numel · size

Sorting Sets

argsort · intersect · ismember · issorted · setdiff · sort · sortrows · union · unique

Shape

cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · squeeze · tril · triu · vertcat

Creation

colon · eye · false · fill · inf · linspace · logspace · magic · meshgrid · nan · ones · peaks · rand · randi · randn · randperm · range · true · zeros

Indexing

find · ind2sub · sub2ind

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how isempty is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.