how to take out specific month from data

4 次查看(过去 30 天)
sir i have 95 year daily model output rainfall data form 2006-1-1 to 2100-12-31.i want to take out nov to feb which include leap years. i have program for this.this is working perfectly for who does not include leap year but i want to include leap years then please suggest me what will change in this program for this. in between 2006 to 2100 have 24 leap years but my data include only 23 leap years,this is not not include end(last) leap year. this is daily data.sir my precipitaion data size is ( 20x22x34698) (lat,lon.time) for india region.sir please help me. this is include leap years.please help me.thank you
dten = datenum([2006 1 1 ;2100 12 31])
[~,M] = datevec(dten(1):dten(2));
xx = find(ismember(M,[11 12 1 2]));
[m,n,k] = size(prec_all_years1);
ii = cumsum(eomday(2014,1:12));
x0 = rem(0:k-1,365)+1;
xx_logic = x0 <= ii(2) | x0 > ii(10);
p = prec_all_years1(:,:,xx_logic);
max_rainfall = max(reshape(p,m*n,[]));
  4 个评论
dpb
dpb 2014-4-10
What do you mean by "take out", precisely? You mean you want to remove (or selectively keep) those months' data and ignore the rest? Your M variable and ismember will find those. If you're looking to find the leap years and either keep or discard only them, then do the same kind of thing keeping Y as well and build the logical vector of which year is a leap year for the addressing. That's easily done by
isLpYr=(eomday(Y,2)==29); % logical vector T for Y==leap year
ravi
ravi 2014-4-10
编辑:ravi 2014-4-10
it's mean i want to make another data set for nov to feb from 12 month data (12x16x34675 (lat,lon.time) for india region who include leap years).i want to cut only nov to feb my data set but this program is right only for those who does not include leap year then suggest me what will change in this program for my requirement.please help me,thank you

请先登录,再进行评论。

采纳的回答

dpb
dpb 2014-4-10
编辑:dpb 2014-4-11
As noted above, you were already there--
dten = datenum([2006 1 1 ;2100 12 31]);
[~,M] = datevec(dten(1):dten(2));
p = prec_all_years1(:,:,ismember(M,[11 12 1 2]));
IOW, just throw away all the leap year stuff if don't want it. But if want to go back, the preceding logical vector is much simpler way to select/not select those years than the initial logic.
[Y,M] = datevec(dten(1):dten(2));
p = prec_all_years1(:,:,ismember(M,[11 12 1 2]) & ~(eomday(Y,2)==29));
will select Nov-Feb for the non-leap years in the range of years Y
Look up Using Logicals in Array Indexing in the documentation for more details.
  14 个评论
Poulomi Ganguli
Poulomi Ganguli 2019-6-24
编辑:Poulomi Ganguli 2019-6-24
Hello:
I came across the same issue. My data are arranged in a matrix containing year, month, day and value. If I run this code, I am encountering foll. error message:
The logical indices in position 3 contain a true value outside of the array bounds
dpb
dpb 2019-6-24
Well, the above code is for retrieving from a 3D array, not 2D...you'll need to write the proper expression to match your different storage arrangement. But, can't see your terminal from here so have no definite knowledge to go on.

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2014-4-9
2100 is NOT a leap year; it's the "divided by 100" exception of the "divisible by four" rule. Then there's the 400 yr correction as well but we'll likely not be seeing it.
I am wondering, however, about how you've managed to accumulate daily precipitation data for years from 2015-2100 as yet...

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by