function accumulation = sediment_accumulation(mu, sigma, t_list, ensemble_size)
% sediment_accumulation.m
%
% USAGE: accumulation = sediment_accumulation(mu, sigma, t_list, ensemble_size)
%
% Simulate a random walk for num_steps number of steps.
% Each step is drawn from a normal distribution with mean mu and std sigma.
% Inputs:
%   mu        - mean of step dist.
%   sigma     - std of step dist.
%   num_step  - total number of step walker takes.
%   plot_flag - (optional) value of 0 results in no plot being created. 
%               Other values create figure of walker trajectory. 
%
% Outputs:
%   x - distance from origin after taking num_steps. 

% init matrix of sediment thickness for different time intervals. 
% x(i,j) is the thickness of the ith section that represent the jth time
% interval ( =t_list(j) ).
x = zeros(ensemble_size,length(t_list)); 
for i = 1:length(t_list) % for each time interval
    t = t_list(i);
    ensemble_member = 1;
    while ensemble_member <= ensemble_size % simulate sections until obtain ensemble_size of positive sections
        x_temp = random_walk(mu, sigma, t); % temporary section thickness from RW simulation
        if x_temp > 0 % only for positive section thickness
            x(ensemble_member, i) = x_temp; % store section thickness in matrix
            ensemble_member = ensemble_member + 1; % update sample size
        end
    end
end

accumulation = mean(x); %average over all memebers of the ensemble to obtain accumulation.

