MATLAB: How to take out specific month from data

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,[]));

Best Answer

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.