フィルターのクリア

Converting 2D cell array to 3D matrix

41 ビュー (過去 30 日間)
Lyle Edwards
Lyle Edwards 2023 年 6 月 9 日
コメント済み: Lyle Edwards 2023 年 6 月 10 日
I have a cell that is [8x454] with each element in the cell containing a [900x1] matrix. I would like to convert this cell into a 3 dimensional matrix of size [8x454x900]. Ive tried some things including reshape, cat and permute but can never seem to get it right. Any help would be greatly appreciated!

採用された回答

James Tursa
James Tursa 2023 年 6 月 10 日
編集済み: James Tursa 2023 年 6 月 10 日
E.g.,
MyCell = repmat({(1:4)'},2,3) % small sample data
MyCell = 2×3 cell array
{4×1 double} {4×1 double} {4×1 double} {4×1 double} {4×1 double} {4×1 double}
[m,n] = size(MyCell);
reshape(cell2mat(MyCell(:)').',m,n,[])
ans =
ans(:,:,1) = 1 1 1 1 1 1 ans(:,:,2) = 2 2 2 2 2 2 ans(:,:,3) = 3 3 3 3 3 3 ans(:,:,4) = 4 4 4 4 4 4
size(ans)
ans = 1×3
2 3 4
  1 件のコメント
Lyle Edwards
Lyle Edwards 2023 年 6 月 10 日
This works, thank you so much!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 6 月 9 日
cell2mat(reshape(YourCell, 1, 1,[]))

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by