binning histogram and obtaining the proportions
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
dpb
el 4 de Mayo de 2017
Editada: dpb
el 4 de Mayo de 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.
0 comentarios
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!