フィルターのクリア

How to concatenate a 3D cell array along the 3rd dimension?

13 ビュー (過去 30 日間)
Raphael
Raphael 2020 年 2 月 23 日
コメント済み: Raphael 2020 年 2 月 23 日
Dear experts, I am trying to convert CellArray1 into CellArray2, by concatenating CellArray1 along the third dimension. Any ideas on how to do that efficiently?
CellArray1 =
2×2×3 cell array
val(:,:,1) =
{180×1 double} {180×1 double}
{180×1 double} {180×1 double}
val(:,:,2) =
{180×1 double} {180×1 double}
{180×1 double} {180×1 double}
val(:,:,3) =
{180×1 double} {180×1 double}
{180×1 double} {180×1 double}
CellArray2 =
2×2 cell array
{540×1 double} {540×1 double}
{540×1 double} {540×1 double}
Thank you so much!

採用された回答

Stephen23
Stephen23 2020 年 2 月 23 日
編集済み: Stephen23 2020 年 2 月 23 日
In one line using num2cell, cellfun, and vertcat:
>> C1 = cell(2,2,3); % preallocate cell array.
>> C1(:) = cellfun(@(~)rand(180,1),C1,'uni',0); % fake data.
>> C2 = cellfun(@(c)vertcat(c{:}),num2cell(C1,3),'uni',0);
And checking the first element of C2:
>> size(C2)
ans =
2 2
>> size(C2{1})
ans =
540 1
>> isequal(C2{1},vertcat(C1{1,1,:}))
ans = 1
  1 件のコメント
Raphael
Raphael 2020 年 2 月 23 日
Works perfectly! Thanks!

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

その他の回答 (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