mat2cell
转换array to cell array with potentially different sized cells
Syntax
C = mat2cell(A,dim1Dist,...,dimNDist)
C = mat2cell(A,rowDist)
Description
divides arrayC
= mat2cell(A,dim1Dist,...,dimNDist
)A
成更小的数组单元阵列中C
. Vectorsdim1Dist,...dimNDist
specify how to divide the rows, columns, and (when applicable) higher dimensions ofA
.
divides arrayC
= mat2cell(A,rowDist
)A
into ann
-by-1 cell arrayC
, wheren == numel(rowDist)
.
Input Arguments
|
Any type of array. |
|
Numeric vectors that describe how to divide each dimension of c = mat2cell(x, [10, 20, 30], [25, 25]) divides a 60-by-50 array into six arrays contained in a cell array. For the If the a = rand(3, 0, 4); c = mat2cell(a, [1, 2], [], [2, 1, 1]); |
|
Numeric vector that describes how to divide the rows of |
Output Arguments
|
Cell array. The |
Examples
Divide the 5-by-4 matrixX
into 2-by-3 and 2-by-2 matrices contained in a cell array.
X = reshape(1:20,5,4)' C = mat2cell(X, [2 2], [3 2]) celldisp(C)
This code returns
X = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 C = [2x3 double] [2x2 double] [2x3 double] [2x2 double] C{1,1} = 1 2 3 6 7 8 C{2,1} = 11 12 13 16 17 18 C{1,2} = 4 5 9 10 C{2,2} = 14 15 19 20
DivideX
(created in the previous example) into a 2-by-1 cell array.
C = mat2cell(X, [1 3]) celldisp(C)
This code returns
C = [1x5 double] [3x5 double] C{1} = 1 2 3 4 5 C{2} = 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20