# how to take seasoanal mean

3 vues (au cours des 30 derniers jours)
Muhammad Uswah Pawara le 2 Avr 2022
I have data with 231x141x6408 dimension, it is daily mean data of January, February, and December from 1950-2020. How to take seasonal mean from the data for each year. so I finally obtain data with dimension 231x141x71, please note there are leap years.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Pavan Sahith le 14 Mai 2024
Hello ,
I noticed you're seeking assistance with calculating the seasonal mean of your data.
For that you can refer to this sample code which will guide you.
Since I couldn't access the link provided , created some sample data to work with.
rows = 231;
cols = 141;
% Total days for 71 years, assuming 91 days for non-leap years and 92 for leap years
% Leap years add an extra day: 18 leap years in the range 1950-2020
totalDays = (71 - 18) * 91 + 18 * 92;
data = rand(rows, cols, totalDays);
Create an array to store the seasonal mean results with dimensions 231x141x71.
seasonalMean = zeros(231, 141, 71);
Now, Calculate the mean for the specific months for each year, considering leap years.
startIndex = 1;
for year = 1:71
% Check for leap year
if mod(1950 + year - 1, 4) == 0 && (mod(1950 + year - 1, 100) ~= 0 || mod(1950 + year - 1, 400) == 0)
daysInMonths = 31 + 29 + 31; % Adjust for leap year
else
daysInMonths = 31 + 28 + 31; % Non-leap year
end
endIndex = startIndex + daysInMonths - 1;
% Calculate the seasonal mean for the current year
seasonalMean(:,:,year) = mean(data(:,:,startIndex:endIndex), 3);
% Update the startIndex for the next year
startIndex = endIndex + 1;
end
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by