mat2cell second input parameter(s)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ahmed Hossam
am 19 Apr. 2017
Kommentiert: Ahmed Hossam
am 19 Apr. 2017
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!
0 Kommentare
Akzeptierte Antwort
KL
am 19 Apr. 2017
Bearbeitet: KL
am 19 Apr. 2017
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!