![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/184750/image.jpeg)
How do I average over a number of Histograms?
17 views (last 30 days)
Show older comments
Arghadwip Paul
on 7 Jun 2017
Commented: Shubhani Paliwal
on 17 Nov 2023
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
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/184750/image.jpeg)
So, why don't you start taking small enough time windows and let us know?
John BG
Accepted Answer
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
More Answers (1)
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.
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!