merge 12 rows in 12 matrices to one matrix

조회 수: 1 (최근 30일)
Sewwandhi Chandrasekara
Sewwandhi Chandrasekara 2022년 10월 24일
편집: Alex Hanes 2022년 10월 25일
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

답변 (1개)

Alex Hanes
Alex Hanes 2022년 10월 24일
편집: Alex Hanes 2022년 10월 25일
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.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by