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

조회 수: 2 (최근 30일)
IMC
IMC 2020년 9월 24일
편집: Dana 2020년 9월 24일
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
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
IMC
IMC 2020년 9월 24일
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
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!

Translated by