How to find month wise mean and std from data of many years
Afficher commentaires plus anciens
my data is from 2005 to 2022 containg 7 variables as well as NaN , how I can find month wise mean and std
january
February
March
.
.
december
Réponse acceptée
Plus de réponses (1)
Mathieu NOE
le 4 Mai 2023
hello
try this
T = readtable('data.csv');
data = table2array(T(:,2:end));
dates = T(:,1);
month_mean = mean(data,2);
month_std = std(data,0,2);
% create output table
t = array2table([month_mean month_std],'VariableNames',{'Mmean' 'Mstd'});
Tout = [dates t];
will generate an output table :
Tout =
Var1 Mmean Mstd
__________ ________ _________
01.01.2005 NaN NaN
01.02.2005 NaN NaN
01.03.2005 NaN NaN
01.04.2005 0.11526 0.044447
01.05.2005 0.077879 0.0298
01.06.2005 0.050409 0.024809
2 commentaires
Ritesh
le 4 Mai 2023
Mathieu NOE
le 4 Mai 2023
this is a new attempt
so all data from same month (al years ) are processed
at the end you get 12 mean and std values . I admit I don't use enough more advanced functions but it works too (retime and timetable are not my everyday topic)
Results :
Tout = 12×3 table
Month number Mmean Mstd
____________ ________ ________
1 NaN NaN
2 NaN NaN
3 0.093719 0.049733
4 0.11645 0.050869
5 0.098805 0.058374
6 0.070153 0.044218
7 0.088374 0.066424
8 0.083617 0.04806
9 0.072031 0.040978
10 0.063109 0.04562
11 NaN NaN
12 NaN NaN
T = readtable('data.csv');
data = table2array(T(:,2:end));
TT = table2timetable(T);
dates = (TT.Var1);
mm = month(dates);
tol = 1e-6;
for ci = 1:12
id_cols = (abs(mm-ci)<tol);
% group same month (all years) data in one vector
data_all = data(id_cols,:);
month_mean(ci,1) = mean(data_all(:),'omitnan');
month_std(ci,1) = std(data_all(:),'omitnan');
end
% create output table
m_list = (1:12)';
Tout = array2table([m_list month_mean month_std],'VariableNames',{'Month number' 'Mmean' 'Mstd'});
Catégories
En savoir plus sur Descriptive Statistics and Insights dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!