Place data within a cell in rows
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a table like below where the results data contained in the cell is a string. Is there a way to stack the data within the results cells in rows? I would like to write this table into Excel as table for publication.
OLD TABLE
Left cuneus Left entorhinal
Experiment 1 t = -3.66 p = 0.001 x, y, z = -26.1, -6.2, 52.2 Nvx = 31 t = -3.38 p = 0.002 x, y, z = -48.6, -43.7, 0.7 Nvx = 20
Experiment 2 t = -4.66 p = 0.002 x, y, z = -46.1, -7.2, 52.2 Nvx = 21 t = -7.38 p = 0.003 x, y, z = -48.6, -63.7, 1.7 Nvx = 22
NEW TABLE
Left cuneus Left entorhinal
Experiment 1 t = -3.66 t = -3.38
p = 0.001 p = 0.002
x, y, z = -26.1, -6.2, 52.2 x, y, z = -48.6, -43.7, 0.7
Nvx = 31 Nvx = 20
Experiment 2 t = -4.66 t = -7.38
p = 0.002 p = 0.003
x, y, z = -46.1, -7.2, 52.2 x, y, z = -48.6, -63.7, 1.7
Nvx = 21 Nvx = 22
0 comentarios
Respuesta aceptada
Voss
el 13 de En. de 2022
The attached function may be of some use.
t = table(["t = -3.66 p = 0.001 x, y, z = -26.1, -6.2, 52.2 Nvx = 31"; "t = -4.66 p = 0.002 x, y, z = -46.1, -7.2, 52.2 Nvx = 21"],["t = -3.38 p = 0.002 x, y, z = -48.6, -43.7, 0.7 Nvx = 20"; "t = -7.38 p = 0.003 x, y, z = -48.6, -63.7, 1.7 Nvx = 22"],'variablenames',{'Left_cuneus','Left_entorhinal'})
stack_string(t{1,1})
stack_string(t{2,1})
stack_string(t{1,2})
stack_string(t{2,2})
2 comentarios
Voss
el 14 de En. de 2022
Editada: Voss
el 14 de En. de 2022
I'm not sure about that; I never use tables. I would use a cell array of character vectors or a 2D string array and write that to file.
variable_names = {'Left cuneus' 'Left entorhinal'};
t = table(["t = -3.66 p = 0.001 x, y, z = -26.1, -6.2, 52.2 Nvx = 31"; "t = -4.66 p = 0.002 x, y, z = -46.1, -7.2, 52.2 Nvx = 21"],["t = -3.38 p = 0.002 x, y, z = -48.6, -43.7, 0.7 Nvx = 20"; "t = -7.38 p = 0.003 x, y, z = -48.6, -63.7, 1.7 Nvx = 22"],'variablenames',strrep(variable_names,' ','_'))
N_variables = numel(variable_names);
N_experiments = 2;
s_out = repmat("",5*N_experiments,N_variables+1);
s_out(1,2:end) = string(variable_names);
for i = 1:N_experiments
s_out(5*(i-1)+2,1) = "Experiment " + i;
for j = 1:N_variables
s_out(5*(i-1)+2:5*i,j+1) = stack_string(t{i,j});
end
end
s_out
writematrix(s_out,'test.xlsx');
readtable('test.xlsx')
readcell('test.xlsx')
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets 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!