How to get monthly average from daily data?
Show older comments
So i have this Matrix, consisting of 4 columns: Column 1: Year Column 2: Month Column 3: day (1 to 30) Column 4: Some Value
I want to make monthly average of "some value" without breaking the matrix into some new matrix and calculate mean for each moths matrix seperately then rejoin them. I want to make an average matrix using for loop and find function for each myear seperately. So I dont like to have an average from all the first months of all the years together. Does anyone have an Idea?
I have sth like this, but i donno why it is not working:
k=1
%Calculating Monthly Average
for i=1961:1990 %Years Looping
for j=1:12 %Months Looping
idx=find((date(:,1)==i) & (date(:,2)==j)); %Find all indeces for the specific month
meandata1=mean(date(idx,4),1);
Monthly_Ave(k,:)=[i,j,meandata1;]; %Store in a new matrix the mean values per month
k=k+1;
end
end
5 Comments
jonas
on 27 Sep 2018
When you say monthly average, do you mean over several years or for each single year separately?
Do you want 12 values or 12 times the number of years?
frankovaT
on 27 Sep 2018
jonas
on 27 Sep 2018
If I interpret your addendum correctly, you want 12 values per year. I have modified the answer accordingly, however I'd strongly recommend using a timetable and retime. If you upload some data I'd be happy to demonstrate.
frankovaT
on 27 Sep 2018
jonas
on 27 Sep 2018
and answer updated as promised!
Accepted Answer
More Answers (1)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!