필터 지우기
필터 지우기

how to take seasoanal mean

조회 수: 1 (최근 30일)
Muhammad Uswah Pawara
Muhammad Uswah Pawara 2022년 4월 2일
답변: Pavan Sahith 2024년 5월 14일
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

답변 (1개)

Pavan Sahith
Pavan Sahith 2024년 5월 14일
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!

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by