MATLAB: How I can calculate average of some histograms

histogramimage processing

would you please guide me how I can calculate average of some histograms and then show it on the same histogram? thanks

Best Answer

If the counts are stored in counts1, counts2, counts3, counts4, counts5, and the bin centers or bin edges were fixed (not just the number of bins), then
mean_counts = mean([counts1(:), counts2(:), counts3(:), counts4(:), counts5(:)], 2);
If necessary, calculate the bin centers into bin_centers from the bin edges:
bin_centers = (bin_edges(1:end-1) + bin_edges(2:end)) / 2;
Then to add to the plot in the current axes,
hold on
relative_width = 1;
bar(bin_centers, mean_counts, relative_width);