How to convert data with 3Dimensions to cell array

1 回表示 (過去 30 日間)
Mahendran Subramanian
Mahendran Subramanian 2019 年 10 月 2 日
コメント済み: Guillaume 2019 年 10 月 2 日
I have a data A with 3D dimesions 2 x 5 x 2353 (double) and I would like to change it to the following
A=2353×1 cell
{2×5 double}
{2×5 double}
{2x5 double}
{2x5 double}
{2x5 double}
{2x5 double}
{... double}
Can I use Mat2Cell function ?

採用された回答

Guillaume
Guillaume 2019 年 10 月 2 日
The simplest is:
B = num2cell(A, [1, 2]); %keep rows and columns together, split the pages
This will give you a 1x1x2353 cell array. If you do want a 2353x1 cell array permute the result:
B = permute(num2cell(A, [1, 2]), [3, 2, 1]);
  2 件のコメント
Mahendran Subramanian
Mahendran Subramanian 2019 年 10 月 2 日
Thank you for the answer what if the data A is 2D 2353 x 1 (double) and if I would like to change it to the following
A=2353×1 cell
can I use
B = num2cell (A, [2353]);
?
Guillaume
Guillaume 2019 年 10 月 2 日
No, the inputs to num2cell are the array to split and the dimensions to keep together. Nothing to do with the size of the array. If you want to split each element in an individual cell, then it's simply:
B= num2cell(A);
documentation of num2cell which has plenty of examples.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by