Get bin label associated with 2D histogram of x,y data

조회 수: 1 (최근 30일)
Jasper
Jasper 2013년 2월 21일
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
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
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

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by