How to get the indices of the values inside every bin i.e. histcounts2

24 ビュー (過去 30 日間)
Ole
Ole 2020 年 2 月 14 日
コメント済み: the cyclist 2020 年 2 月 15 日
How to get the indices of x and y for the counts that go into every bin.
x = randn(1,10); y = randn(1,10);
nbins = [8 8];
[C,Xedges,Yedges] = histcounts2(x,y, nbins);
C
C =
0 0 0 1 0 1 0 1
0 0 1 1 0 0 0 0
0 0 0 3 0 0 0 0
0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0
[C,Xedges,Yedges, binX, binY] = histcounts2(x,y, nbins);
binX(3), binY(4) %will give the opposite, in which bin is element x(3) y(4)
  2 件のコメント
Sindar
Sindar 2020 年 2 月 14 日
try discretize
the cyclist
the cyclist 2020 年 2 月 15 日
discretize(x,Xedges)
gives the same result as binX, so I don't think it helps here.

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

採用された回答

the cyclist
the cyclist 2020 年 2 月 15 日
編集済み: the cyclist 2020 年 2 月 15 日
Suppose you want to know which elements are in the bin that is 8 down and 6 across. Then
binToFind = [8 6];
[tf,loc] = ismember([binX',binY'],binToFind,'row')
idx = find(loc)
idx gives the indices you want. It will be an empty vector if there are no elements in that bin.

その他の回答 (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