How to split data set into multiple bins and perform condition statement on bins
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a logical data set and I am trying to divide it into 31 bins but my data points are not evenly distributing and I need it to be divided into 31 bins so that I can then run an if statement that counts the total number of ones in each bin and compares it to a condition.
댓글 수: 0
답변 (1개)
Matt J
2022년 3월 24일
편집: Matt J
2022년 3월 24일
Use the discretize() command.
to assign bin labels to each of your data points.
댓글 수: 11
Matt J
2022년 3월 25일
편집: Matt J
2022년 3월 25일
So my example should give me a count of 3.
No, that would depnd on how the data is split into subsets. Even without randomization, a subset may contain no ones, like in the following, where the subsets are sequential.
Data = [0 0 0 1 0 1 1 0 1 1 1 0];
binLabels=[1 1 1 2 2 2 2 3 3 3 3 3];
numOnes=accumarray(binLabels',Data')
overallCount = sum(numOnes>=1)
Once again, because you haven't specified the details of the processing with enough care and detail, we get a result you don't expect. Perhaps you meant for the subsets to be interleaved. That does give your expected result:
binLabels=[1 2 3 1 2 3 1 2 3 1 2 3];
numOnes=accumarray(binLabels',Data')
overallCount = sum(numOnes>=1)
참고 항목
카테고리
Help Center 및 File Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!