Hey all
I have 34 variable in my workplace like this:
precip_1982_daily
precip_1983_daily
precip_1984_daily
precip_1985_daily
…
precip_2015_daily
I want to use this if code below:
if size(precip_1982_daily,3)==365 month_lengths=[31 28 31 30 31 30 31 31 30 31 30 31];%non-leap year
else month_lengths=[31 29 31 30 31 30 31 31 30 31 30 31];%leap year
endprecip_1982_monthly=mat2cell(precip_1982_daily,size(precip_1982_daily,1),size(precip_1982_daily,2),month_lengths);%divide into 1 cell per month
precip_1982_monthly=cellfun(@(x) nansum(x,3),precip_1982_monthly,'UniformOutput',false);%find mean for each month
precip_1982_monthly=cell2mat(precip_1982_monthly);%convert back to 3D array
Best Answer