MATLAB: How to take out extreme event annually from the data.

sir i have program who calculate extreme event for whole 95 years but i want to calculate extreme event annually (it mean 365 then 365 ….each separate years) then what will be change in this program for doing this? my data size is (prec_all_years) 20x22x34675(lon,lat,time).this is daily data.
prec_all_years = prec_all_years*86400; % rainfall in mm/day
xx = []
for ii= 1:95;
for i = 1:length(X1);
for j = 1:length(Y1);
xx = [xx (i-1)*[1:365]];
prec1 = prec_all_years(i,j,xx);
inds1 = find(prec1 >=64.5 & prec1 <= 124.5); inds2 = find(prec1 > 124.5 & prec1 <=244.5); inds3 = find(prec1 > 244.5);
hr(i,j) = length(inds1); vhr(i,j)= length(inds2); ehr(i,j)= length(inds3);
end end end % now find frequency of rainfall in different regions
% western region
xe = [13:20]; ye = [11:16]; xw = [1:8]; yw = [11:16]; xn = [5:9]; yn = [15:20]; xs = [5:9]; ys = [3:7];
% eastern region
freq_east_hr = hr(xe,ye);
count_hr_east = sum(freq_east_hr(:))
freq_east_vhr = vhr(xe,ye);
count_vhr_east = sum(freq_east_vhr(:))
freq_east_ehr = ehr(xe,ye);
count_ehr_east = sum(freq_east_ehr(:))

Best Answer

Slightly new approach, given your comment on the previous answer. This one creates hr, vhr, and ehr, which are 20-by-22-by-95 (lat/lon/year) arrays holding the counts over each year, for each lat/lon location. These are then summed over all locations to give count_X_east, which are 95-element vectors (one total for each year).
prec_all_years = prec_all_years*86400; % rainfall in mm/day
bins = [64.5 124.5 244.5 Inf];
% Reshape into lat/lon/day/year, and bin over 3rd dimension (days)
counts = histc(reshape(prec_all_years,20,22,365,95),bins,3);
% Extract the counts for each of the 3 categories
hr = squeeze(counts(:,:,1,:));
vhr = squeeze(counts(:,:,2,:));
ehr = squeeze(counts(:,:,3,:));
% Extract a region
xe = 13:20; ye = 11:16;% xe is x for east,ye is y for east
% Extract counts for each category
count_hr_east = sum(reshape(hr(xe,ye,:),[],95));
count_vhr_east = sum(reshape(vhr(xe,ye,:),[],95));
count_ehr_east = sum(reshape(ehr(xe,ye,:),[],95));