フィルターのクリア

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 Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by