how to take out specific month from data

6 Ansichten (letzte 30 Tage)
ravi
ravi am 9 Apr. 2014
Kommentiert: dpb am 24 Jun. 2019
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 Kommentare
dpb
dpb am 10 Apr. 2014
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 am 10 Apr. 2014
Bearbeitet: ravi am 10 Apr. 2014
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 10 Apr. 2014
Bearbeitet: dpb am 11 Apr. 2014
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 Kommentare
Poulomi Ganguli
Poulomi Ganguli am 24 Jun. 2019
Bearbeitet: Poulomi Ganguli am 24 Jun. 2019
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 am 24 Jun. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 9 Apr. 2014
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...

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by