Trouble concatenating a cell.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Paul Safier
el 21 de Sept. de 2023
Comentada: Voss
el 21 de Sept. de 2023
I want to concatenate the cell in the image such that rows 1,2 and10 are expanded, i.e. rows 1 and 2 each become 4 rows. Row 10 should become 2 rows. Thus, when done, the cell will be size [20 4] and not [13 4].
Ultimately I want this data into a table to write to disk as a csv. I plan to use writetable...
I'm not having any luck with cell concatenation operations gleaned online. Any suggestions?
Thanks.
0 comentarios
Respuesta aceptada
Voss
el 21 de Sept. de 2023
Editada: Voss
el 21 de Sept. de 2023
Here's one way to make a table out of it:
% a cell array like yours:
tst = { ...
"n"+string(randi(10,4,1)),zeros(4,1),rand(4,1),rand(4,1); ...
"n"+string(randi(10,4,1)),zeros(4,1),rand(4,1),rand(4,1); ...
"n1",0,-3000,-3000; ...
"n2",0,-4000,-4300; ...
"n"+string(randi(10,2,1)),zeros(2,1),rand(2,1),rand(2,1); ...
"n3",0,-4400,-4500; ...
}
% vertcat each column, store in args cell to be sent to table:
N = size(tst,2);
args = cell(1,N);
for ii = 1:N
args{ii} = vertcat(tst{:,ii});
end
T = table(args{:})
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!