Calculate the area overlap of two histograms with different bin widths

i am looking for a script which can calculate the overlap area of two histograms with different bins widths. The area which i would need is in green in the image below
Does anyone know a script? I ve found a lot of scripts for histograms but not one for my task. Thank you!

2 commentaires

Give a numerical example. Otherwise we'll just give you one more script that you will say is "not one for your task."
mick strife
mick strife le 11 Déc 2014
Modifié(e) : mick strife le 11 Déc 2014
For example i have 2 histograms like in the image below. Both have different bins. As you can see they overlap. What i need is the overlap area between these histograms. I hope it is clear now. Thank you!

Connectez-vous pour commenter.

Réponses (1)

I'm not sure what the bars above the histograms are - it's not clear what bins they correspond to. There is certainly overlap elsewhere, for example in the 0.49 - 0.51 range.
Isn't the "overlapped" curve merely the curve that is the minimum of the two individual histograms ? I'm pretty sure it is. So can't you just sum that?
minOfHists = min([counts1; counts2], [], 1);
overlappedHist = sum(minOfHists);
Then just divide by whatever baseline you want to normalize it.

5 commentaires

mick strife
mick strife le 11 Déc 2014
Modifié(e) : mick strife le 11 Déc 2014
Yes, in principle you are right. But the histograms have different bin widths and therefore i cant use just the minimum bin area. i have uploaded a new image above. To be accurate i would need the green area. Thanks for your effort.
@addition In my final work i have histograms which are normalized to an area of 1. also minimum and maximum are the begin and the end of a histogram.
Just observing here, but is there a reason you can’t interpolate (using interp1 and the 'nearest' method) one (with the largest bin widths) in terms of the other (with the smallest bin widths, so that both are in terms of the smallest bin widths) and then do the comparison (which would seem to be the minimum of the two in the range of interest)? Your measurements are going to be approximate anyway.
That would be my approach.
My problem is not that i dont know how to calculate it :-) i ve thought that may be somebody has already programed it and therefore i would save a lot of time and could invest it in other tasks. But thanks for your hint. I think it could be useful later.
No, I don't think getting overlap of histograms where the histograms have different bin widths is that common of a thing to do, so you're probably stuck doing it yourself, which you said you know how to do.
My pleasure. Interpolating bins might be difficult (I’ve never had reason to do it, so I have no personal experience with interpolating histograms), but I would encourage you to experiment, first with the bin edges, then with the bin centres, to see which would provide the best approximation. You can determine that simply by overplotting the results on your existing histograms. A visual fit is likely as good as any statistical measure at determining the precision of your interpolation.
Then do the min calculation.

Connectez-vous pour commenter.

Commenté :

le 11 Déc 2014

Community Treasure Hunt

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

Start Hunting!

Translated by