How to bin a simple number array?
古いコメントを表示
Hello,
I'm reading a simple number array from a .txt file (all integers) using:
fileID = fopen('control.txt','r');
formatSpec = '%d';
A = fscanf(fileID,formatSpec);
Now I want to bin these integers into a several groups:
Group 1: integers from 21 to 100;
Group 2: integers from 101 to 500;
Group 3: integers from 501 to 1000;
Group 4: integers from 1001 to infinity (max number unknown).
I'm also interested in finding the range (how many numbers) of each group.
Thank you!
採用された回答
その他の回答 (1 件)
Steven Lord
2016 年 7 月 25 日
1 投票
Use the histcounts function and specify a vector of edges.
4 件のコメント
That One
2016 年 7 月 25 日
Steven Lord
2016 年 7 月 26 日
Take a look at the documentation for histcounts for some examples.
Star Strider
2016 年 7 月 26 日
You have already come close to defining them:
Group 1: integers from 21 to 100;
Group 2: integers from 101 to 500;
Group 3: integers from 501 to 1000;
Group 4: integers from 1001 to infinity (max number unknown).
Use the max function to help you define the upper edge.
Experiment with to get the result you want.
Steven Lord
2016 年 7 月 26 日
Or just specify Inf as the right endpoint of the last bin.
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!