フィルターのクリア

How to split data set into multiple bins and perform condition statement on bins

12 ビュー (過去 30 日間)
Keaton Looper
Keaton Looper 2022 年 3 月 24 日
編集済み: Matt J 2022 年 3 月 25 日
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.

回答 (1 件)

Matt J
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 件のコメント
Keaton Looper
Keaton Looper 2022 年 3 月 25 日
With my example I want the data to be distributed into 3 subsets of data. I then want it to count the total amount of ones in the set and if it is great than 1 count that event as a one and then take the total count of events. So my example should give me a count of 3.
Matt J
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')
numOnes = 3×1
0 3 3
overallCount = sum(numOnes>=1)
overallCount = 2
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')
numOnes = 3×1
3 1 2
overallCount = sum(numOnes>=1)
overallCount = 3

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by