1 function [F,X]=ecdf(h,Y)
2 % ECDF empirical cumulative function
3 % NaN's are considered Missing values and are ignored.
6 % calculates empirical cumulative distribution functions (i.e Kaplan-Meier estimate)
9 % without output arguments plots the empirical cdf, in axis gca.
12 % must be a vector or matrix, in case Y is a matrix, the ecdf for every column is computed.
14 % see also: HISTO2, HISTO3, PERCENTILE, QUANTILE
17 % $Id: ecdf.m 8223 2011-04-20 09:16:06Z schloegl $
18 % Copyright (C) 2009,2010 by Alois Schloegl <alois.schloegl@gmail.com>
19 % This function is part of the NaN-toolbox
20 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
22 % This program is free software; you can redistribute it and/or modify
23 % it under the terms of the GNU General Public License as published by
24 % the Free Software Foundation; either version 3 of the License, or
25 % (at your option) any later version.
27 % This program is distributed in the hope that it will be useful,
28 % but WITHOUT ANY WARRANTY; without even the implied warranty of
29 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 % GNU General Public License for more details.
32 % You should have received a copy of the GNU General Public License
33 % along with this program; If not, see <http://www.gnu.org/licenses/>.
35 if ~isscalar(h) || ~ishandle(h) || isstruct(h),
43 if SW, SW = isfield(Y,'datatype'); end;
44 if SW, SW = strcmp(Y.datatype,'HISTOGRAM'); end;
50 f = [zeros(1,yc);cumsum(Y.H,1)];
59 DIM = min(find(sz>1));
60 if isempty(DIM), DIM = 1; end;
62 if DIM==2, Y=Y.'; DIM = 1; end;
67 f = zeros(size(Y,1)+1,size(Y,2));
69 f(:,k)=[0:size(Y,1)]'/N(k);
74 if ~isempty(h), axes(h); end;