# Reducing the number of count/values in each bin in MATLAB

2 views (last 30 days)
IMC on 24 Sep 2020
Edited: Dana on 24 Sep 2020
Hello,
How can I reduce the no. of values/count that fall into each bin? I am using histcount function
Intervals_CTT = [-100:60]
1) Count_Liquid = (Count_Liquid + histcounts(CTT_liquid, Intervals_CTT))
~ Below is the output of above line. I want to reduce the count, or it can be zero values in the first few bins that would be okay too. 2) Count_Liquid = histcounts(CTT_liquid, Intervals_CTT);
And using the above line (2) I don't get any values in the bins. All the bins contain zero.
Thank you.

Dana on 24 Sep 2020
Edited: Dana on 24 Sep 2020
In this line:
Count_Liquid = (Count_Liquid + histcounts(CTT_liquid, Intervals_CTT))
the variable Count_Liquid is computed using itself (it appears on both sides). I don't think that's what you want.
Also, the number of elements of CCT_liquid that lie inside a given bin is what it is. The only way to change the counts is to change the bins themselves.
Why not let MATLAB do the binning automatically?
nbins = 200; % number of bins (where more bins => smaller bins => less in each bin)
[Count_Liquid,edges] = histcounts(CTT_liquid, nbins); % get counts and the bin edges

IMC on 24 Sep 2020
By using the above line I got zero values in all the bins.
Secondly, I specified the 'Intervals_CTT' because this is temperature and I want my values (CTT_liquid) to plot against it.
Dana on 24 Sep 2020
Sorry, I made a copy-paste mistake in previous post. It should be:
nbins = 200; % number of bins (where more bins => smaller bins => less in each bin)
[Count_Liquid,edges] = histcounts(CTT_liquid, nbins); % get counts and the bin edges
Do you still get zeros? If so, the problem is with your CTT_liquid variable.
The fact that when you did
Count_Liquid = histcounts(CTT_liquid, Intervals_CTT);
you got all zeros is telling you that CTT_liquid doesn't have values in any of the bins you created. Try what I suggested above, which lets MATLAB create the bins automatically given the desired total number of bins. Then inspect the bins it created (whose edges are returned in edges). Is the range of these bin edges unexpected? For example, you seem to expect the elements of CTT_liquid to be between -100 and 60. If edges only contains elements between, say, 100 and 200, then that would explain why you got zeros before: the data you're counting isn't in the range you're expecting.