Multiply values by the number of days in each month

3 ビュー (過去 30 日間)
BN
BN 2020 年 5 月 11 日
回答済み: Star Strider 2020 年 5 月 12 日
Dear all,
I have a 41x35x360 array namely C. So the C has 360 pages; while 360 represents months from 1-1-1989 (to 12-31-2018 which is 360 months). I want to multiply the value inside each page to the number of days in each month (considering leap and non-leap years). If it is matter 41 and 35 are latitude and longitude, respectively.
C = rand(41,35,360) ; % random 3d data
For example:
C(41, 35, 1) * number of days in January 1989
C(41, 35, 2) * number of days in February 1989
...
C(41, 35, 360) * number of days in December 2018
Thank you

採用された回答

Star Strider
Star Strider 2020 年 5 月 12 日
Use the eomday function to find the number of days in each month:
yearv = 1989:2018;
for k = 1:numel(yearv)
daysInMonth(k,:) = [yearv(k), eomday(yearv(k), 1:12)];
end
This creates a matrix where the first column is the year and columns 2:13 are the days in each month of that year.
Adapt it to provide the information you need for your array.

その他の回答 (1 件)

the cyclist
the cyclist 2020 年 5 月 12 日
C = rand(41,35,360) ; % random 3d data
daysNonLeap = [31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31];
daysLeap = daysNonLeap;
daysLeap(2) = 29;
daysFourYear = [daysNonLeap; daysNonLeap; daysNonLeap; daysLeap];
daysThirtyYear = [repmat(daysFourYear,7,1); daysNonLeap; daysNonLeap];
C = C .* permute(daysThirtyYear,[3 2 1]);

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by