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

1 Ansicht (letzte 30 Tage)
Odysseas Makariou
Odysseas Makariou am 28 Mai 2022
Kommentiert: Voss am 28 Mai 2022
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.

Akzeptierte Antwort

Voss
Voss am 28 Mai 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by