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
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
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 件のコメント
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 Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!