필터 지우기
필터 지우기

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by