Specifying dimensions in mat2cell

8 ビュー (過去 30 日間)
Nancy Hammond
Nancy Hammond 2019 年 9 月 2 日
コメント済み: Nancy Hammond 2019 年 9 月 3 日
a 4 by 5 MatriX
A =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
The Mathwork example divide sA into two 2-by-3 and two 2-by-2 subarrays:
C = mat2cell(A,[2 2],[3 2])
What are the indices here in the dimension statement:
Does [2,2] refer to 2 tables w two rows each
Does [3,2] specify the first set of tables has 3 rows, the second set 2 rows.
I can't understand or see the pattern in how the dimensions are set in mat2cell
Thank you, Nancy
  3 件のコメント
Nancy Hammond
Nancy Hammond 2019 年 9 月 2 日
Correction: Should read
Does [3,2] specify the first set of tables has 3 cols, the second set 2 cols.
Walter Roberson
Walter Roberson 2019 年 9 月 2 日
"Does [3,2] specify the first set of tables has 3 cols, the second set 2 cols."
Yes.

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 2 日
C = mat2cell(A,[2 2],[3 2])
means that numeric matrix A is to be broken up into cells.
The first row of cells is to have [2 2][1] -> 2 rows. The second row of cells is to have [2 2][2] -> 2 rows. This is a total of sum([2 2]) = 4 rows, and it is an error if A does not have that many rows.
The first column of cells is to have [3 2][1] -> 3 columns. The second column of cells is to have [3 2][2] -> 2 columns. This is a total of sum([3 2]) = 5 columns, and it is an error if A does not have that many columns.
Thus, the sizes of the entries in C will be all combinations of [2 2] with [3 2], so
{size [2, 3], size [2, 2] -> leading 2 from the first 2 in [2 2]
size [2, 3], size [2, 2]} -> leading 2 from the second 2 in [2 2]
  1 件のコメント
Nancy Hammond
Nancy Hammond 2019 年 9 月 3 日
Thank you, Walter. At last, very clear. Nancy

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by