-
Notifications
You must be signed in to change notification settings - Fork 0
/
findintervalbin.m
28 lines (26 loc) · 985 Bytes
/
findintervalbin.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
function [ bins, bincount, min ] = findintervalbin( values, max, ...
bincount, min )
% FINDINTERVALBIN returns the bin indices for the vector VALUES such that
% the lowest bin index is the underflow and the highest bin index is the
% overflow.
% The range from MIN (excluded) to MAX (included) is split into BINCOUNT
% many equivalent bins. Underflows (including exact values of MIN) are put
% in the first bin (underflow bin), overflows in the last bin (overflow
% bin).
% The first inputs are mandatory. BINCOUNT is by default 102, MIN is by
% default 0.
%
% Copyright 2021, C. Minz. BSD 3-Clause License.
if nargin < 3
bincount = 102;
end
if nargin < 4
min = 0;
end
underflow = 1;
overflow = bincount;
bins = ceil( ( bincount - 2 ) * double( values - min ) ...
/ ( max - min ) ) + 1;
bins( bins < 1 ) = underflow;
bins( bins > overflow ) = overflow;
end