Get bin label associated with 2D histogram of x,y data
3 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am looking for a way to extract the bin labels from a large matrix of x and y coordinates. So the basic form of it would look like this:
A(:,1) = randi([50 550],500,1); % random x coord
A(:,2) = randi([50 250],500,1); % random y coord
Hist = hist3(A, [25 25]);
Is it possible to get the bin label associated with each of my 500 datapoints? Bigger picture is that all these coordinates in fact have some value and I want to average all these values for the bin they were found in based on their coordinates, before processing them further. Thanks for any help/advice!
J
edit: no I don't want the count of the number of coords in each bin, I need the bin label (say i,j and running from 1,1 to 25,25) of each pair of coordinates x,y. Hope this makes sense... thanks!
1 件のコメント
Doug Hull
2013 年 2 月 21 日
By Bin label, do you mean the count of the number of data points in each bin? Please edit your originial question to clarify.
回答 (1 件)
Sean de Wolski
2013 年 2 月 21 日
Yea, you'll be able to do this using histc() and accumarray():
x = ceil(rand(1000,1)*10); %x
y = ceil(rand(1000,1)*10); %y
z = rand(1000,1); %values
edges = 1:10; %some edges to bin along
[~, idxx] = histc(x,edges); %Which x bin?
[~, idxy] = histc(y,edges); %Which y bin?
averages = accumarray([idxx idxy],z,[],@mean); %Build the average matrix
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!