forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindFractionAboveValue.m
More file actions
28 lines (24 loc) · 969 Bytes
/
findFractionAboveValue.m
File metadata and controls
28 lines (24 loc) · 969 Bytes
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 value = findFractionAboveValue( data, fraction )
% value = findFractionAboveValue( data, fraction )
%
% This function finds the value where fraction amount of the data is
% above this value.
% For example, if fraction is 0.35, then this function finds the value
% where approximately 35% of the data is above this value.
%
% Written by Nicholas Dwork - Copyright 2017
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
if nargin < 1
disp( 'Usage: value = findFractionAboveValue( data, fraction )' );
return
end
nData = numel( data );
lowerValue = min( data(:) );
upperValue = max( data(:) );
f = @( value ) fraction - sum( data(:) >= value ) / nData;
value = binarySearch( f, lowerValue, upperValue, 'tol', 1d-8, 'nMax', Inf );
end