Place data within a cell in rows
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2022-1-13
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 个评论
Voss
2022-1-14
编辑:Voss
2022-1-14
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')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!