geomaverage.m (609B)
1 function avg=geomaverage(x,yrs,nanversion); 2 3 % geomaverage.m -- Takes the geometric average of x over the yrs periods 4 % Implement by exponentiating the average of the logs. 5 % 6 % yrs=[1 10; 7 % 1 5; 8 % 6 10]; 9 % 10 % x=TxN vector ==> compute the averages of x over the yrs periods. 11 % 12 % nanversion==1 ==> use meannan instead of mean to avg existing values. 13 14 if exist('nanversion')~=1; nanversion=0; end; 15 avg=zeros(size(yrs,1),size(x,2)); 16 for i=1:size(yrs,1); 17 if nanversion==1; 18 avg(i,:)=exp(meannan(log(x(yrs(i,1):yrs(i,2),:)))); 19 else; 20 avg(i,:)=exp(mean(log(x(yrs(i,1):yrs(i,2),:)))); 21 end; 22 end;