RunMat
GitHub

cell — Create MATLAB cell arrays, including 'like' prototypes, with RunMat's modern builtin pipeline.

cell constructs cell arrays—containers that can hold heterogeneous values in each element. Every cell starts out containing an empty value: by default the empty double array [], or an empty value that matches a 'like' prototype when the prototype lives on the host. GPU-backed prototypes currently fall back to empty double arrays on the host. RunMat mirrors MATLAB's behaviour for scalar and arbitrary size forms (cell, cell(n), cell(m, n, p, ...), cell([m n p ...]), cell(size(A)), and cell(___, 'like', prototype)).

How cell works in RunMat

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

How cell runs 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

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

These functions work well alongside cell. Each page has runnable examples you can try in the browser.

cellfun, struct, gpuArray, gather, cell2mat, cellstr, mat2cell

Open-source implementation

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

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.