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!