필터 지우기
필터 지우기

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
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
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
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
andrepiz 2024년 2월 7일
you can use histweight available on MATLAB exchange.
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.

카테고리

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