Clear Filters
Clear Filters

How do I average over a number of Histograms?

17 views (last 30 days)
So, I have 100 histogram plots each for different time instant. To analyze the system, I need a histogram plot which is the average of all these plots. How do I do it? I don't want to do it by image processing and all that. Can I do something like generating the histograms with equal number of bins and add the frequencies and then do the average and re-plot the average histogram. But, the problem will be in the histograms of the plots for the different instants, the range might be different. Please help. Thank you.
  2 Comments
John BG
John BG on 8 Jun 2017
Edited: John BG on 8 Jun 2017
Hi Arghadwip Paul
In general, one can average partial histograms (the different times you mention) when the stochastic process is ergodic.
This happens if the average value doesn't change throughout each sample, and is not null.
From
So, why don't you start taking small enough time windows and let us know?
John BG
Arghadwip Paul
Arghadwip Paul on 8 Jun 2017
Ergodic means when the process will be independent of the initial state. I have done simulations till the time when I don't observe significant changes in my system. I would now want to average over the data of time instants(delta t=10^(-4)). What do you think?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jun 2017
Do not histogram with an equal number of bins: histogram with consistent edges to the bins. Then you can just put all the results together and mean() as appropriate.
In the below example, numedges-1 and edges(1:end-1) relates to the fact that the number of bins produced by histcounts is one fewer than the number of edges, because the final edge marks the end of the range.
num_datasets = 100;
edges = sort(rand(1, 14) * 5);
numedges = length(edges);
counts = zeros(numedges-1, num_datasets);
for dataset_idx = 1 : 100
counts(:, dataset_idx) = histcounts( datasets{dataset_idx}, edges );
end
avg_counts = mean(counts);
bar(edges(1:end-1), avg_counts)
  4 Comments

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 7 Jun 2017
Generate each set of bin counts using histcounts with the same set of bin edges for each call. Once you have the bin counts for each trial, add them together and call histogram with the bin counts and bin edges to plot it.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!