merge 12 rows in 12 matrices to one matrix

1 view (last 30 days)
I have daily RF data for 55 years and I managed to get mean monthly RF for 55 years for each months seperately. I want to get all mean monthly RF data into one table. How can i do it.
My daily RF data is 365X55
mean for January is 1X55
mean for February is 1X55
Now I need January to December in one table 12X55
Rather than taking one by one mean values for each months, is it easy way to get directly 12X55 matrix?
Please help, Thanks in advance

Answers (1)

Alex Hanes
Alex Hanes on 24 Oct 2022
Edited: Alex Hanes on 25 Oct 2022
I'll define some fake data:
nMonths = 12;
dailyRF = rand(365,55); % fake data array
idxDays = [31; 28; 31; 30; 31; 30; ... % days in each month
31; 31; 30; 31; 30; 31];
idx1 = cumsum(idxDays) + 1 -idxDays; % start index
idx2 = cumsum(idxDays); % end index
avgMonth = zeros(12,55); % pre-allocate
% Loop over the number of months and take average over entire month:
for k = 1:nMonths
avgMonth(k,:) = mean(dailyRF(idx1(k):idx2(k),:),1);
end
Edit: The code is now formatted properly. Original post from my phone.

Categories

Find more on Tables 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!