RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • cell
    • cell2mat
    • cell2struct
    • cellfun
    • cellstr
    • mat2cell
    • num2cell

cell2mat — Concatenate compatible cell-array blocks into one dense array.

cell2mat assembles array blocks using the cell grid as a block layout.

Syntax

A = cell2mat(C)

Inputs

C
Type
Any
Required
Yes
Description
Cell array containing compatible array blocks.
NameTypeRequiredDefaultDescription
CAnyYes—Cell array containing compatible array blocks.

Returns

A
Type
Any
Description
Dense array assembled from the cell contents.
NameTypeDescription
AAnyDense array assembled from the cell contents.

Errors

RunMat:cell2mat:TooManyOutputs
When
More than one output is requested.
Message
cell2mat: too many output arguments
RunMat:cell2mat:InvalidInput
When
The input is not a cell array.
Message
cell2mat: expected a cell array input
RunMat:cell2mat:InvalidContents
When
The cell contents cannot form one dense array.
Message
cell2mat: cell contents are not compatible for concatenation
IdentifierWhenMessage
RunMat:cell2mat:TooManyOutputsMore than one output is requested.cell2mat: too many output arguments
RunMat:cell2mat:InvalidInputThe input is not a cell array.cell2mat: expected a cell array input
RunMat:cell2mat:InvalidContentsThe cell contents cannot form one dense array.cell2mat: cell contents are not compatible for concatenation
RunMat:cell2mat:SizeExceededThe output shape or storage exceeds platform limits.cell2mat: resulting matrix exceeds platform limits
—An internal allocation or storage invariant fails.cell2mat: internal error

Block concatenation

cell2mat(C) concatenates compatible numeric, logical, complex, or character blocks from a cell array. The cell grid selects each block's position in the result.

Along every dimension of the cell grid, blocks sharing the same grid coordinate must agree on their extent in that dimension. Extents may differ between coordinates, including page coordinates of an N-D cell grid, and those extents add to form the output shape. Only block dimensions beyond the cell-grid rank must agree throughout the grid. Empty blocks contribute zero extent.

Classes and storage

The result keeps the content class. Fixed-width integer blocks retain exact storage; compatible mixed integer blocks use the leftmost nonempty integer class and saturating assignment conversion. Scalar doubles cannot be combined with int64 or uint64 blocks.

Strings, nested cells, structs, and objects are not valid contents. Character blocks produce a character array and must remain two-dimensional.

Execution

Cell arrays are host containers. Resident numeric elements are gathered before concatenation, and the result is host-resident. cell2mat ends an active fusion group.

An empty cell array returns a 0-by-0 double array.

Examples

Tile an N-D cell grid with unequal row and page extents

C = cell(2,1,2);
C{1,1,1} = reshape(1:4,[1 2 2]);
C{2,1,1} = reshape(5:12,[2 2 2]);
C{1,1,2} = reshape(13:18,[1 2 3]);
C{2,1,2} = reshape(19:30,[2 2 3]);
A = cell2mat(C);

Expected output:

A has shape 3-by-2-by-5

Convert scalar cells

C = {1, 2; 3, 4};
A = cell2mat(C);

Expected output:

A is [1 2; 3 4]

Concatenate rectangular blocks

C = {[1 2], [3 4 5]; [6 7], [8 9 10]};
A = cell2mat(C);

Expected output:

A is a 2-by-5 matrix

Preserve logical storage

C = {true(2,1), false(2,1)};
A = cell2mat(C);

Expected output:

A is a 2-by-2 logical array

Concatenate complex blocks

C = {1+2i, [3+4i 5+6i]};
A = cell2mat(C);

Expected output:

A contains three complex values

Join character rows

C = {'foo', 'bar'; 'baz', 'qux'};
A = cell2mat(C);

Expected output:

A has rows 'foobar' and 'bazqux'

Tile N-dimensional blocks

C = {ones(2,2,3), 2*ones(2,1,3)};
A = cell2mat(C);

Expected output:

A has shape 2-by-3-by-3

Convert an empty cell grid

C = {[], []; [], []};
A = cell2mat(C);

Expected output:

A is a 0-by-0 double array

Preserve wide integer values

C = {0x0020000000000001u64, 0xFFFFFFFFFFFFFFFFu64};
A = cell2mat(C);

Expected output:

A is an exact 1-by-2 uint64 array

Using cell2mat with coding agents

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

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

FAQ

Which cell contents can cell2mat concatenate?⌄

Numeric, logical, complex, and character arrays are supported. Every nonempty block must belong to one compatible fundamental kind; nested cells, strings, structs, and objects are rejected.

Must every block have the same shape?⌄

No. Widths may differ between cell-grid columns and heights may differ between rows. Extents must agree wherever blocks share the corresponding grid coordinate.

What happens when cells contain empty arrays?⌄

Empty blocks contribute zero extent along their tiling dimension while retaining the selected content class. A completely empty cell array returns a 0-by-0 double array.

Does cell2mat preserve GPU residency?⌄

Not currently. Resident elements gather and the concatenated result is allocated on the host.

Related Cells functions

cell · cell2struct · cellfun · cellstr · mat2cell · num2cell

Source you can read

Every RunMat function's source is public. Read exactly how cell2mat is executed, line by line, in Rust.

  • View the source for cell2mat 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Block concatenation
  • Classes and storage
  • Execution
  • Examples
  • Tile an N-D cell grid with unequal row and page extents
  • Convert scalar cells
  • Concatenate rectangular blocks
  • Preserve logical storage
  • Concatenate complex blocks
  • Join character rows
  • Tile N-dimensional blocks
  • Convert an empty cell grid
  • Preserve wide integer values
  • Using cell2mat with coding agents
  • FAQ
  • Related Cells functions
  • Source you can read
  • About RunMat