Commit 48e95f24 authored by Nicolas Rodriguez's avatar Nicolas Rodriguez

Add new file

parents
%
% Copyright 2019-2020 LIST (Luxembourg Institute of Science and Technology), all right reserved.
%
% Author: Nicolas Rodriguez (nicolas.bjorn.rodriguez@gmail.com)
%
function [prct,frc]=age_metrics(p,dT,T_group,age_prctiles)
% calculates the percentiles of a given age distribution and the fractions of
% water younger than given age labels
% pre-allocation
prct=NaN(1,length(age_prctiles)+1);
frc=NaN(length(T_group),1);
P=cumsum(p*dT); % cumulative age distr
frc(1:sum(T_group<length(P)*dT),1)=P(max(1,round(T_group(T_group<length(P)*dT)/dT))); % fractions of water younger than T
x=dT:dT:dT*length(p); % ages in abscisse
for k=1:length(age_prctiles)
temp=find(P<age_prctiles(k));
if isempty(temp)
prct(1,k)=NaN;
else
prct(1,k)=temp(end)*dT; % age percentiles in hours
end
end
prct(1,k+1)=trapz(x,x.*p); % mean age in hours
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment