-
Notifications
You must be signed in to change notification settings - Fork 6
/
MF_quantile.m
36 lines (33 loc) · 1015 Bytes
/
MF_quantile.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
function q = MF_quantile(y,p)
% _
% Quantiles for univariate data
% FORMAT q = MF_quantile(y,p)
%
% y - a vector of sample data from a random variable
% p - a k x 1 vector of percentages between 0 and 1
%
% q - a k x 1 vector of quantiles for these percentages
%
% FORMAT q = MF_quantile(y,p) returns quantiles for data y at cut-offs p.
% For example, the q for p = 0.5 would be the median, a value chosen such
% that 50% of the data are smaller than this threshold.
%
% Author: Joram Soch, BCCN Berlin
% E-Mail: [email protected]
%
% First edit: 31/07/2014, 11:50 (V0.1/V4)
% Last edit: 13/11/2014, 12:00 (V0.2/V7)
% Sort data
%-------------------------------------------------------------------------%
ys = sort(y);
% Get quantiles
%-------------------------------------------------------------------------%
q = NaN(size(p));
for j = 1:length(p)
i = 1;
n = numel(ys);
while (i/n) < p(j)
i = i + 1;
end;
q(j) = ys(i);
end;