mat2cell second input parameter(s)

1 回表示 (過去 30 日間)
Ahmed Hossam
Ahmed Hossam 2017 年 4 月 19 日
コメント済み: Ahmed Hossam 2017 年 4 月 19 日
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.
  1 件のコメント
Ahmed Hossam
Ahmed Hossam 2017 年 4 月 19 日
You're marvellous! Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by