Finding average data from a large data matrix
Afficher commentaires plus anciens
Hello,
I have a data matrix in the following format:
Row 1 is the years from 1990 to 2000
Row 2 is the month
Row 3 is the day
Row 4 is the data
Ex:
1990 1990 1990 1990…..until 2000
1 1 1 1 1 1 1 1…2 2 2 2 2 2….3 3 3 3
1 2 3 4 5 6
How can I calculate the average data of each month (ie. all the jan, feb, together)? The problem that I am encountering is finding a systematic way of dividing the data, given its format.
Thanks in advance
Réponse acceptée
Plus de réponses (2)
data = [1990 1990 1990 1990 1995 1995 1995 1995;
1 1 2 2 1 1 2 2;
1 2 1 2 1 2 1 2;
3 5 7 4 6 8 1 9]'
avgData = groupsummary(data(:,4),[data(:,1),data(:,2)],'mean')
This is probably easier to understand if you turn your data into a table.
dataT = array2table(data,'VariableNames',["Year","Month","Day","Data"])
avgDataT = groupsummary(dataT,["Year","Month"],"mean","Data")
One more may to do this is if you turn your date info into a datetime variable
dataT2 = table(datetime(data(:,1:3)),data(:,4),'VariableNames',["Date","Data"])
avgDataT2 = groupsummary(dataT2,"Date","month","mean","Data")
dpb
le 18 Nov 2022
tData=array2table(X.','VariableNames',{'Year','Month','Day','Data'});
tMonthAvg=rowfun(@mean,tData,'GroupingVariables',{'Month'}, ...
'InputVariables','Data','OutputVariableNames','MonthAverage');
1 commentaire
A= [2000 2000 2000 2001 2001;
1 1 2 1 1;
5 3 8 9 7]'
groupsummary(A(:,3),[A(:,1) A(:,2)],'mean')
Catégories
En savoir plus sur Logical 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!