필터 지우기
필터 지우기

determining bin placement, histograms

조회 수: 5 (최근 30일)
Matlabhelp
Matlabhelp 2016년 9월 28일
댓글: Image Analyst 2020년 8월 25일
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에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by