Clear Filters
Clear Filters

how to take seasoanal mean

1 view (last 30 days)
Muhammad Uswah Pawara
Muhammad Uswah Pawara on 2 Apr 2022
Answered: Pavan Sahith on 14 May 2024
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.
Link of the data
https://drive.google.com/file/d/1PeZKZZIJN7LBXxRn9omSyQN3UU33TBNX/view?usp=sharing

Answers (1)

Pavan Sahith
Pavan Sahith on 14 May 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
You can also refer to the following MathWorks documentation to learn more about 'mean' and 'mod':
I hope this information helps you move forward with your task!

Categories

Find more on Entering Commands in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!