mat2cell second input parameter(s)

1 次查看(过去 30 天)
Hier:
https://ch.mathworks.com/help/matlab/ref/mat2cell.html
I have a problem to fully understand the second, third, fourth and so on parameter for this Matlab function:
C = mat2cell(A,dim1Dist,...,dimNDist) divides array A into smaller arrays within cell array C. Vectors dim1Dist,...dimNDist specify how to divide the rows, columns, and (when applicable) higher dimensions of A.
Assume I have a (7 x 3) Matrix B. What's wrong of typing:
CellarrX = mat2cell(A,[1:2:7])
and meaning, that I'd like to have a CellarrX with:
(2 x 3) (2 x 3) (2 x 3) (1 x 3)
?!
If somebody has a good explanation for this, I'd be very thankful!

采纳的回答

KL
KL 2017-4-19
编辑:KL 2017-4-19
Hi Ahmed,
From the example on the documentation, when you say
c = mat2cell(x, [10, 20, 30], [25, 25])
you should expect 'c' to have 6 (3*2) effective cell arrays. (3*2) comes from the size of the last two arguments in the above command. [10, 20, 30] specifies the number of rows in each resulting cell arrays and [25, 25] specifies columns. Now in your case you'd like to have 4 cell arrays but all of them have same number of columns. So the last two parameters should be of size 4 and 1.
X = rand(7,3)
C = mat2cell(X, [2 2 2 1], 3);
celldisp(C)
Now the last two parameters specify how you wanna distribute rows and columns respectively. Hope this was helpful. (the pictorial representation from the doc page helps you visualize the distribution quite easily.)
KL.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Signal Processing Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by