How to reshape nested cell arrays in a table

조회 수: 7 (최근 30일)
Blue
Blue 2019년 8월 14일
댓글: Blue 2019년 8월 14일
Hi,
How does one reshape nested cell arrays in Matlab ? Let's say I have something like this:
t = table({1:24}, {1:48}, {1:48}, {1:48});
t = reshape(t.Var3, [4, 12])
How can I reshape Var2, Var3 and Var4 into 4x12 arrays instead of 1x48 ?

채택된 답변

madhan ravi
madhan ravi 2019년 8월 14일
편집: madhan ravi 2019년 8월 14일
t(:,2:4)=varfun(@(x) {reshape(x{:},4,12)},t(:,2:4))

추가 답변 (1개)

the cyclist
the cyclist 2019년 8월 14일
편집: the cyclist 2019년 8월 14일
Here is one way:
t.Var2 = {reshape(t.Var2{:},4,12)}
and analogously for Var3 and Var4.
Parsing what that is doing, from the inside out:
  • Getting at the numeric array contents, using curly brackets, because Var2 is a cell array
  • Doing the reshape
  • Putting that reshaped numeric array back into a cell array
  • Storing that new cell array into Var2 again
Seems like an odd use of a table to me, but who am I to judge?

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by