Name table columns with variable index
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pablo SERIS
el 27 de Abr. de 2022
Comentada: Pablo SERIS
el 28 de Abr. de 2022
I'll take to explain a 3 columns table but I actually have around 100 columns.
I have a 3 columns table, with each column named with a label Ux,Uy,Uz and filled with 18000 values
I want to calculate mean value and standard deviation for each column and put it in a 6 columns table with columns named like [Uxmean,Uxstd,Uymean,Uystd,...]
Here is my program.
file = uigetfile();
tab = readtable(file);
varnames = tab.Properties.VariableNames(1:end);
doub = table2array(tab(:,[1:end]));
for i = [1:width(doub)]
cell(2*i-1) = (mean(doub(:,i)));
cell(2*i) = (std(doub(:,i)));
end
tab =array2table(cell);
% for i = [1:width(doub)]
% tab.Properties.VariableNames(2*i-1)=varnames(i) "mean"
% tab.Properties.VariableNames(2*i)=varnames(i) "std"
% end
It works until the commented lines, when i try to add the index "mean" to odd columns and "std" to even columns
I'm very new on Matlab so i probably forgot some details and there is for sure a easier method so tell me.
Thank you!
0 comentarios
Respuesta aceptada
Chunru
el 27 de Abr. de 2022
Editada: Chunru
el 27 de Abr. de 2022
tab = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/980210/MATWORKS.csv');
head(tab)
varnames = tab.Properties.VariableNames(1:end)
m_tab = varfun(@mean, tab)
s_tab =varfun(@std, tab)
output = [m_tab s_tab]
idx = [0; 3]+(1:3); idx=idx(:);
output=output(:, idx)
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!