필터 지우기
필터 지우기

How can I un-nest a cell array of different type cells?

조회 수: 6 (최근 30일)
Odysseas Makariou
Odysseas Makariou 2022년 5월 28일
댓글: Voss 2022년 5월 28일
Hello, I have a 1x6 cell array where each element is a 22x1 cell or double array (the cell arrays contain text)
I want to expand the whole cell and then convert it to a table of the following format
X 1 Y 1 Z 1
X 2 Y 2 Z 2
X 3 Y 3 Z 3
X 4 Y 4 Z 4
.
.
.
.
X 22 Y 22 Z 22
I used cell2table and writecell but it doesn't help
Essentially I want to end up with a 22x6 table with letters on columns 1,3,5 and numbers on columns 2,4,6, and then and then convert the table to a txt file
Thank you.

채택된 답변

Voss
Voss 2022년 5월 28일
C = {{'X';'X';'X'} [1;2;3] {'Y';'Y';'Y'} [1;2;3] {'Z';'Z';'Z'} [1;2;3]} % your cell array
C = 1×6 cell array
{3×1 cell} {3×1 double} {3×1 cell} {3×1 double} {3×1 cell} {3×1 double}
T = table(C{:}) % make a table T
T = 3×6 table
Var1 Var2 Var3 Var4 Var5 Var6 _____ ____ _____ ____ _____ ____ {'X'} 1 {'Y'} 1 {'Z'} 1 {'X'} 2 {'Y'} 2 {'Z'} 2 {'X'} 3 {'Y'} 3 {'Z'} 3
writetable(T) % write the table to a text file
% check the file:
ls
T.txt
type T.txt
Var1,Var2,Var3,Var4,Var5,Var6 X,1,Y,1,Z,1 X,2,Y,2,Z,2 X,3,Y,3,Z,3

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by