cell2mat

Joins the contents of a cell array into one ordinary array.

Category: Language Fundamentals > Data Types

Syntax

M = cell2mat(C)

Concatenates the cell contents, rows and columns in cell order.

Description

Each row of cells is concatenated horizontally and the resulting rows are stacked vertically, so the pieces in a row must have the same number of rows and the pieces in a column the same number of columns.

Contents must all be of the same class and cannot be cell arrays. An empty cell array gives [].

Input arguments

C
Cell array whose contents are numeric, logical, char or struct, all of one class, with sizes that fit together.

Output arguments

M
The concatenated array.

Example

Blocks into a matrix

C = {[1 2], 3; [4 5], 6};
M = cell2mat(C)
Output
M = 2×3

     1     2     3
     4     5     6

See also

num2cell cell cat horzcat vertcat