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

6 次查看(过去 30 天)
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