RunMat
GitHub

cell — Create empty cell arrays in MATLAB and RunMat.

cell constructs heterogeneous containers where each element starts as empty ([] by default). It supports scalar, multi-dimension, size-vector, and size(A) forms, plus 'like' prototypes, with behavior aligned to MATLAB and RunMat.

Syntax

C = cell()
C = cell(n)
C = cell(sz)
C = cell(m, n, ...)
C = cell("like", prototype)
C = cell(sz, "like", prototype)
C = cell(m, n, ..., "like", prototype)

Inputs

NameTypeRequiredDefaultDescription
nSizeArgYesSquare size.
szSizeArgYesSize vector.
dimsSizeArgVariadicDimension sizes.
like_kwStringScalarYes"like"Like keyword.
prototypeLikePrototypeYesPrototype value used to infer element class.

Returns

NameTypeDescription
CAnyOutput cell array.

Errors

IdentifierWhenMessage
RunMat:cell:InvalidInputInput arguments or option forms are invalid.cell: invalid input arguments
RunMat:cell:InvalidSizeRequested size arguments are invalid or unsupported.cell: invalid size arguments
Internal cell allocation or conversion failed.cell: internal error

How cell works

  • cell (with no arguments) returns a 0×0 empty cell array.
  • cell(n) returns an n×n cell array whose elements default to the empty value.
  • cell(m, n, p, ...) accepts any number of size scalars and returns an N-D cell array whose dimensions match the arguments.
  • cell(sz) or cell(size(A)) accepts a numeric size vector of any length. A single-element vector produces an m×1 cell array; longer vectors create higher-dimensional cell arrays matching the provided extents.
  • cell(___, 'like', prototype) copies the prototype's size when no explicit dimensions are supplied and fills each element with the empty value that matches the prototype's class (for example logical empty arrays, complex empties, or empty strings). When the prototype is a gpuArray, RunMat keeps the host-empty double fallback until GPU-resident cell storage ships.
  • Size arguments must be finite, non-negative integers that are representable in double precision.

Does RunMat run cell on the GPU?

Cell arrays live on the CPU heap because each element can contain arbitrarily typed values that may require garbage-collected storage. When cell is invoked inside a fused GPU expression RunMat terminates the fusion group, gathers any GPU-resident size inputs, and creates the cell array on the host. 'Like' prototypes that refer to gpuArray inputs are honoured for shape inference. Each cell currently receives an empty double array even if the prototype itself is a gpuArray; this fallback will disappear once device-side cell residency lands. Once the acceleration layer adds true GPU cells, providers can register hooks without changing user code.

GPU memory and residency

No. Cell arrays are created on the host regardless of the residency of the size arguments. If the inputs happen to live on the GPU (for example, a gpuArray size vector), RunMat gathers those values before allocating the cell array. The result is always a host cell array; downstream code can still place tensors or gpuArrays inside individual cells as needed.

Examples

Creating a square cell array of empty placeholders

C = cell(3);
size(C)

Expected output:

ans =
     3     3

Creating a rectangular 2-by-4 cell array

C = cell(2, 4);
class(C)

Expected output:

ans =
    'cell'

Creating a 3-D cell array

C = cell(2, 3, 4);
size(C)

Expected output:

ans =
     2     3     4

Matching the size of an existing matrix

A = ones(5, 2);
C = cell(size(A));
size(C)

Expected output:

ans =
     5     2

Creating a cell array using a 'like' prototype

proto = logical.empty(0, 0);
C = cell(2, 3, 'like', proto);
cellfun(@isempty, C)

Expected output:

ans =
     1     1     1
     1     1     1

Using a column size vector

sz = [4; 1];
C = cell(sz);
size(C)

Expected output:

ans =
     4     1

Verifying that every cell starts with []

C = cell(2, 2);
isequal(C{1,1}, [], C{2,2}, [])

Expected output:

ans = logical
     1

Using cell with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how cell changes the result.

Run a small cell example, explain the result, then change one input and compare the output.

FAQ

What values do new cells contain?

Each cell starts with an empty value. By default that is the empty double array []. When you supply a 'like' prototype, RunMat chooses the matching empty logical, complex, string, character, or cell value instead. GPU-backed prototypes currently fall back to empty double arrays on the host until device-resident cell elements are supported.

Are negative or fractional sizes allowed?

No. Every size argument must be a finite, non-negative integer that can be represented exactly in double precision.

Can I create zero-sized cell arrays?

Yes. You can use cell(0), cell(0, n), or supply a size vector containing zeros. RunMat returns an empty cell array with the requested shape.

Do GPU prototypes change how cell behaves?

A 'like' prototype that resides on the GPU is gathered automatically. Shape inference follows the prototype, and each cell receives an empty double array on the host while GPU cell storage is still under development.

What about N-dimensional cell arrays?

RunMat supports N-dimensional cell arrays. Supply as many scalar dimensions or size-vector entries as you need and the builtin constructs a cell array with that exact shape. Trailing singleton dimensions are preserved so downstream code can introspect the full size vector.

Does cell copy data from existing containers?

No. The builtin only allocates empty cells. Populate the elements afterwards with assignments such as C{1,2} = magic(3);.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how cell 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.