function [boxmean,tim,dep]=idma_box_mean(p,w); % % IDMA_BOX_MEAN computes monthly averages (over 1992-2011) of all profiles % in p that passed all QCs (i.e. such that weight w>0); both p and % w are in MITprof format as obtained using idma_box_subset; % boxmean, tim, dep are two dimensional arrays (w. month, depth indices) % % Example: box_l=[-180 -140]; box_L=[-10 10]-30; box_D=[0 300]; % [prof_T,prof_Testim,prof_Tweight]=idma_box_subset(box_l,box_L,box_D); % [boxmean,tim,dep]=idma_box_mean(prof_T,prof_Tweight); % figureL; pcolor(tim,-dep,boxmean); colorbar; demoSTATS=1;%set this to one to activate display of results at one level %%define time and depth arrays tim=1992+[0.5:239.5]/12; dep=p.prof_depth; [dep,tim]=meshgrid(dep,tim); %%mask out points that did not pass all QCs p.prof(w.prof==0)=NaN; %%compute averages boxnb=NaN*zeros(240,p.nr); boxmean=NaN*zeros(240,p.nr); boxmedian=NaN*zeros(240,p.nr); boxstd=NaN*zeros(240,p.nr); for yy=1992:2011; for mm=1:12; dd=[datenum(yy,mm,0) datenum(yy,mm+1,0)]; tt=(yy-1992)*12+mm; % tmp1=MITprof_subset(p,'date',dd); tmp1=tmp1.prof; % boxnb(tt,:)=sum(~isnan(tmp1),1); boxmean(tt,:)=nanmean(tmp1,1); boxmedian(tt,:)=nanmedian(tmp1,1); boxstd(tt,:)=nanstd(tmp1,1); % end; end; %%display results if demoSTATS; figure; kk=2; subplot(3,1,1); plot(tim(:,kk),boxnb(:,kk)); legend('sample size','Location','NorthWest'); subplot(3,1,2); plot(tim(:,kk),boxmean(:,kk)); ylabel('degree C'); hold on; plot(tim,boxmedian(:,kk),'r'); legend('sample mean','sample median','Location','NorthWest'); subplot(3,1,3); plot(tim(:,kk),boxstd(:,kk)); ylabel('degree C'); legend('sample std','Location','NorthWest'); end;