Binning data from two columns using one column as category for second column

Hi all,
So I am trying to do this via loops but i am not getting anywhere and i am sure that there is a quicker way to solve this problem. I have two columns of data, Radius and Volume, and I wanted to bin the Volume according to the values of the Radius. So for example, if R is the first column of values and V is the second column
A = [ 1 8
2 7
3 9
4 3
5 4
6 6
7 5
8 6
9 6
10 6
11 3
12 2
13 1
14 1
15 3
16 4
]
will be binned as
B = [ 5 31
10 29
15 10
]
So the bin labels are the values of the Radius, and the second column contains the sum of the Volumes in that Radius range.
Many thanks

댓글 수: 3

Please explain in some detail how you get ‘B’ out of ‘A’.
So the first column in matrix B is the radius binned with a bin size of 5 (so 5, 10, 15, 20, 25, 30) and the second column is the sum of the values of the volume within each radius range ( so all the volumes for radius was under 5 are summed etc)

댓글을 달려면 로그인하십시오.

답변 (1개)

[~,i] = histc(X,edges)
Result = accumarray(Y,i,[max(i) 1],@sum)

댓글 수: 2

Thanks, I am trying to use this but am having an error message. I assume X= A(:,1) and Y = A(:,2) and edges = bin size?
Thanks again
Almost correct! See the help of HISTC about the meaning of the second input argument ( edges).

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2016년 6월 3일

댓글:

2016년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by