mat2cell
Splits an array into a cell array of sub-blocks.
Category: Language Fundamentals > Data Types
Syntax
C = mat2cell(A, r)
Splits A along the rows into blocks of r(1), r(2), ... rows, keeping all columns.
C = mat2cell(A, r, c)
Splits along rows and columns, giving a numel(r)-by-numel(c) cell array.
Description
mat2cell is the inverse of concatenation: [C{:,:}] style joins undo it. It is the usual way to cut a matrix into uneven pieces. When the sums in r or c do not match the size of A, the call is an error.
Input arguments
A- Array of any type.
r, c- Vectors with the number of rows, and of columns, of each block. Their sums must equal the size of
Ain that dimension.
Output arguments
C- Cell array whose element
C{i,j}is a block ofA.
Example
Cutting a 4-by-4 matrix
A = magic(4);
C = mat2cell(A, [2 2], [3 1]);
C{1,1}
C{2,2}
Output
ans = 2×3
16 2 3
5 11 10
ans = 2×1
12
1