-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistwc.m
37 lines (37 loc) · 972 Bytes
/
histwc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% HISTWC Weighted histogram count given number of bins
%
% This function generates a vector of cumulative weights for data
% histogram. Equal number of bins will be considered using minimum and
% maximum values of the data. Weights will be summed in the given bin.
%
% Usage: [histw, vinterval] = histwc(vv, ww, nbins)
%
% Arguments:
% vv - values as a vector
% ww - weights as a vector
% nbins - number of bins
%
% Returns:
% histw - weighted histogram
% vinterval - intervals used
%
%
%
% See also: HISTC, HISTWCV
% Author:
% mehmet.suzen physics org
% BSD License
% July 2013
function [histw, vinterval] = histwc(vv, ww, nbins)
minV = min(vv);
maxV = max(vv);
delta = (maxV-minV)/nbins;
vinterval = linspace(minV, maxV, nbins)-delta/2.0;
histw = zeros(nbins, 1);
for i=1:length(vv)
ind = find(vinterval < vv(i), 1, 'last' );
if ~isempty(ind)
histw(ind) = histw(ind) + ww(i);
end
end
end