mat2cell
Converts a 2D matrix, m, to a cell array, R.
Syntax
R = mat2cell(m)
R = mat2cell(m, v1)
R = mat2cell(m, v1, v2)
Inputs
- m
- Type: matrix
- v1 (optional)
- Dimension which specifies how the rows of m should be split. The value or the sum of the elements of v1 should be equal to the number of rows of m.
- v2 (optional)
- Dimension which specifies how the columns of m should be split. The value or the sum of the elements of v2 should be equal to the number of columns of m.
Outputs
- R
- Type: cell
Examples
Default dimensions:
m = reshape(1:20, 5,4);
R = mat2cell(m)
R =
{
[1,1] [Matrix] 5 x 4
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
}
Specifying row dimensions:
m = reshape(1:20, 5,4);
R = mat2cell(m, [2,3])
R =
{
[1,1] [Matrix] 2 x 4
1 6 11 16
2 7 12 17
[2,1] [Matrix] 3 x 4
3 8 13 18
4 9 14 19
5 10 15 20
}
Specifying row and column dimensions:
m = reshape(1:20, 5,4);
R = mat2cell(m, [2,3], [3,1])
R =
{
[1,1] [Matrix] 2 x 3
1 6 11
2 7 12
[1,2] [Matrix] 2 x 1
16
17
[2,1] [Matrix] 3 x 3
3 8 13
4 9 14
5 10 15
[2,2] [Matrix] 3 x 1
18
19
20
}