% given a data sample x, produces the cumulative frequency counts
% i.e. how many times x was greater than or equal to some value
% the vector a will return the values, and 
% b will be the cumulative counts

function  [a,b] = cumulativecounts(x)

x = round(x);
minvalue = min(x)
maxvalue = max(x)
bins = minvalue:1:maxvalue;
values = zeros(size(bins));

for i=1:length(x)
    j = x(i)-minvalue+1;
    values(j) = values(j)+1;
end

bins = bins(values>0);
b = values(values>0);
values = values(values>0);
b(length(values)) = values(length(values));
for i=length(values)-1:-1:1
    b(i) = b(i+1) + values(i);
end

a = bins;