Histogram, find edges for bins of same size

4 ビュー (過去 30 日間)
Raphaël
Raphaël 2018 年 5 月 15 日
コメント済み: Raphaël 2018 年 5 月 15 日
Hi,
I have an array filled with a lot of different number values. I want to classify those values. histcounts allows me to find evenly spaced bins with there edges.
What I'm interested though is finding the right uniform edges for my bins that will give me bins filled with the same number of values.
For exemple let's say I have those values I want to put in 3 bins :
A = [8 2 3 4 1 5 6 8 2 1]
The anwser would be :
bin1 = [1,3[ : 4 values
bin2 = [3,6[ : 3 values
bin3 = [6,9[ : 3 values
Is there a function doing that. I know how to do it with a big for loop but that will be pretty slow to calculate.
Thanks!
RMT

採用された回答

Image Analyst
Image Analyst 2018 年 5 月 15 日
Sounds like homework - is it? Here's a hint. First sort your values with sort(), then use cumsum() and find() to find the bin edges closest to a uniform number of counts per bin. Pretty easy, but if you still need help, let me know.
  1 件のコメント
Raphaël
Raphaël 2018 年 5 月 15 日
Not homework. Actually for research but I can always use help to better code things, like remembering that the sort function exists.
B = sort(A(:));
Edges = [B(1:length(B)/100:end)]; % 100ish bins
Edges(end) = B(end); % Making sure all data is including.
Should work fine, thanks. Now I just hope sort works fast enougth.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by