Azzera filtri
Azzera filtri

binning histogram and obtaining the proportions

2 visualizzazioni (ultimi 30 giorni)
jenka
jenka il 4 Mag 2017
Modificato: dpb il 4 Mag 2017
Dear all, I have a quick question. I have histogram and now suppose a new observation comes in and I would like to know which bin in my histogram does it belong to. I then would like to return the proportion of that particular bin. The bin proportion corresponds to the number of observations falling into that bin divided by the total number. Thank you all in advance.

Risposte (1)

dpb
dpb il 4 Mag 2017
Modificato: dpb il 4 Mag 2017
Simplest is probably to just return the bin of the observation via histcounts or histc, whichever you're using with the same bin edges vector as created the original.
[~,~,bin]=histcounts(newX,oldEdgesVector);
Or, it's a lookup using the edges vector
bin=fix(interp1(oldEdgesVector,1:length(oldEdgesVector),newX));
Note interp1 will return interpolated value; return integer portion to get bin. 'nearest' will round, so don't want that. 'previous' may yield same result; I didn't test; I'd probably use the former to be sure had same internal logic w/o worrying about details.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by