% Compute the cumulative average and the error on the mean

% Expects data in the 100-element vector `data'

% e.g. data = load('100hz.txt');



r = zeros(100,1);

for i = 1:100

    % Calculate the cumulative mean

    sum = 0;

    for j = 1:i

        sum = sum + data(j); 

    end

    r(i) = sum/i;

end



% Standard deviation of the parent distribution

std_dev = sqrt(var(data));

mean_error = std_dev./sqrt([1:100]);



errorbar(1:100,r,mean_error,'o');

xlim([0 100]);

grid on;

xlabel('Partial sum index, j');

ylabel('Cumulative average r_c(j)');

