Reducing the number of count/values in each bin in MATLAB
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Dana
2020-9-24
编辑:Dana
2020-9-24
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
2 个评论
Dana
2020-9-24
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!