Is there any way to scale histogram elements so instead of simple count get weighted sum within bins?
조회 수: 2 (최근 30일)
이전 댓글 표시
Let's say I have an array of values: xy=[11,12,13,14,15,11] and an array of bins xyuni=[11,12,13,14,15] and an array of intensities int=[1,1,1,1,1,0.5].
What I would like to calculate is a histogram of xy values within the bins xyuni scaled by the intensities int, so the output I would like to get is:
[1.5,1,1,1,1].
Is there a simple way of doing this? Using histc, I can get the uniform-weighted histogram and bin indices from:
[hstres,binindices] = histc(xy,xyuni)
which gives
histres=[2,1,1,1,1] binindices=[1,2,3,4,5,1]
but I can't think of an easy way to scale by intensity. In reality I have really big arrays so am hoping to avoid a loop (the simple way would be to just loop over bin indices and sum/scale by intensity within the loop to calculate the weighted histogram that way but that would take too long with my really long arrays).
Any suggestions for a vectorized solution?
댓글 수: 1
Jemima Puddleduck
2016년 6월 20일
편집: Jemima Puddleduck
2016년 6월 20일
I would like to know the answer to this question too!!!
https://uk.mathworks.com/matlabcentral/answers/291105-how-to-make-histogram-with-volume-instead-of-frequency
답변 (2개)
Azzi Abdelmalek
2014년 12월 5일
편집: Azzi Abdelmalek
2014년 12월 5일
Edit
xy=[11.1,12.3,13.2,14.2,15.5,11.8]
xyuni=[11,12,13,14,15,16]
int=[1,1,1,1,1,0.5]
[a,b]=histc(xy,xyuni)
c=accumarray(b',int')
out=[c;zeros(numel(a)-numel(c),1)]
댓글 수: 3
topolowa
2016년 9월 1일
Hi Azzi, thanks for your coment. How would you do it if you want to bin X and Y coordinates scaled using Z values. X, Y, Z are vectors. thanks a lot!
andrepiz
2024년 2월 7일
The call would be:
[bins, counts, edges] = histweight(xy, int)
Note that it is not vectorized and bins must be uniformly spaced.
Example for random points attached.
Disclaimer: I am the author of the toolbox.
댓글 수: 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!