determining bin placement, histograms

3 次查看(过去 30 天)
Good evening
I'm using the method of determining bin placement for a histogram and was wondering if this was correct
N = 5;
edges = [0.4,0.8,1.2,1.6,2];
[N,edges,bin] = histcounts(value,'BinMethod','integers');
value = my array. I was wondering if for each edge that each value in my array will go into each corresponding bin. I wasn't sure how the " N ", or " Bin " part of the code works and need some clarification. To clarify also i'd all values at less than 0.4 to be in a bin and then every number below 0.8 to 0.4 to be in a 2nd bin and so forth
  1 个评论
Image Analyst
Image Analyst 2020-8-25
Original question in case he deletes it like other posts:
Good evening
I'm using the method of determining bin placement for a histogram and was wondering if this was correct
N = 5;
edges = [0.4,0.8,1.2,1.6,2];
[N,edges,bin] = histcounts(value,'BinMethod','integers');
value = my array. I was wondering if for each edge that each value in my array will go into each corresponding bin. I wasn't sure how the " N ", or " Bin " part of the code works and need some clarification. To clarify also i'd all values at less than 0.4 to be in a bin and then every number below 0.8 to 0.4 to be in a 2nd bin and so forth

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2016-9-28
Since you have a set of desired bin edges, I would pass those into histcounts (or histogram if you want to see the results graphically) as the second input and remove the 'BinMethod' parameter name/value pair.
[N, edgesOut, bin] = histcounts(value, edges);
You should see that edgesOut is the same as edges.
If you want a bin before the first value in edges, add -Inf at the start of your edges vector.
[N, edgesOut, bin] = histcounts(value, [-Inf, edges]);
Then the first bin will contain those elements in value whose value is in the range [-Inf, 0.4). Similarly, if you want a bin after the last edge, add Inf at the end to catch values in the range [2, Inf].
  2 个评论
Matlabhelp
Matlabhelp 2016-9-28
Do i have to specify 'N' or 'Bin'?, or are those already accounted for because i have already stated what they are equal to.
Steven Lord
Steven Lord 2016-9-28
If you specify the edges explicitly, you don't need to specify the number of bins as an input. In this case histcounts and histogram compute the number of bins as one fewer than the number of edges.
If you specify the edges explicitly, you don't need to specify 'BinMethod' as an input either. The 'BinMethod' parameter allows you to specify what algorithm histcounts should use to calculate where the bin edges should be. Since you explicitly told histcounts where the bin edges should be, it shouldn't try to calculate new edges but should use what you told it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by