Place data within a cell in rows
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Voss
il 13 Gen 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 Commenti
Voss
il 14 Gen 2022
Modificato: Voss
il 14 Gen 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')
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!