cell — Create a cell array whose elements begin as empty arrays.
cell allocates a host cell array with a requested shape and empty elements.
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
n- Type
SizeArg- Required
- Yes
- Description
- Square size.
sz- Type
SizeArg- Required
- Yes
- Description
- Size vector.
sizes- Type
SizeArg- Required
- Variadic
- Description
- Size vector or individual dimension sizes.
like- Type
StringScalar- Required
- Yes
- Default
"like"- Description
- RunMat prototype selector.
prototype- Type
LikePrototype- Required
- Yes
- Description
- Prototype for result shape or empty element representation.
Returns
C- Type
Any- Description
- Preallocated cell array.
Errors
RunMat:cell:TooManyOutputs- When
- More than one output is requested.
- Message
cell: too many output arguments
RunMat:cell:InvalidInput- When
- The argument or option form is invalid.
- Message
cell: invalid input arguments
RunMat:cell:InvalidSize- When
- A requested size is invalid or cannot be represented.
- Message
cell: invalid size arguments
RunMat:cell:Internal- When
- Cell allocation encounters an inconsistent internal shape.
- Message
cell: internal allocation error
Shapes
cell() is RunMat's nonconflicting shorthand for an empty 0-by-0 cell array. The form is accepted under either compatibility policy because it does not replace documented behavior.
cell(n) creates an n-by-n cell array. Separate scalar sizes create an N-dimensional result, while a numeric row vector supplies the complete size. One-element inputs use the square form. Trailing singleton dimensions after dimension two are omitted from the stored shape.
Negative finite sizes become zero. Fractional, nonfinite, nonnumeric, column-vector, unrepresentable, and overflowing size forms return structured errors before allocation.
Initial values
Each cell created by a compatible constructor contains an independent empty 0-by-0 double array. Populate cells later with brace assignment.
RunMat's like extension selects the empty element representation and, when no explicit size is present, the outer shape. The extension is rejected under a MATLAB compatibility pin.
Execution
Cell arrays are host containers and end GPU fusion. In RunMat mode, a resident numeric size control can be gathered from its owning provider before host allocation; MATLAB compatibility mode rejects that extension before provider access.
Examples
Create an empty cell array
C = cell();Expected output:
C is a 0-by-0 cell arrayCreate a square cell array
C = cell(3);Expected output:
C is a 3-by-3 cell arrayCreate a rectangular cell array
C = cell(2, 4);Expected output:
C is a 2-by-4 cell arrayUse an existing array size
A = ones(5, 2);
C = cell(size(A));Expected output:
C has the same 5-by-2 shape as ACreate an N-dimensional cell array
C = cell(2, 3, 4);Expected output:
C is a 2-by-3-by-4 cell arrayUse exact integer size controls
sz = uint64([4 1]);
C = cell(sz);Expected output:
C is a 4-by-1 cell arraySelect an empty element representation
prototype = false(2, 3);
C = cell(2, 'like', prototype);Expected output:
Each cell contains an empty logical arrayUsing 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 does a newly allocated cell contain?⌄
Every compatible constructor cell contains its own empty 0-by-0 double array.
Can a cell array have a zero dimension?⌄
Yes. Any zero size produces an empty cell array with the normalized requested shape.
Are negative or fractional sizes allowed?⌄
Finite fractional sizes are invalid. Signed negative sizes become zero. All eight integer classes are decoded exactly, and allocation fails if the element count exceeds platform limits.
Can size controls reside on the GPU?⌄
The documented constructor is host-only. In RunMat mode, the named GPU-size extension can gather a resident size control before allocating the host cell array.
What about N-dimensional cell arrays?⌄
Supply separate scalar dimensions or a numeric row size vector. Trailing singleton dimensions after dimension two are omitted from the stored shape.
Does cell copy values from another array?⌄
No. Size inputs describe only the outer shape; the optional RunMat prototype chooses shape or empty representation, not payload values.
Related Cells functions
Source you can read
Every RunMat function's source is public. Read exactly how cell is executed, line by line, in Rust.
- View the source for cell 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.