function cdfplot(X,colour,LogScale)
% cdfplot(X) 
% displays a plot of the Empirical Cumulative Distribution Function 
% (CDF) of the input array X in the current figure. The empirical 
% CDF y=F(x) is defined as the proportion of X values less than or equal to x.
% If input X is a matrix, then cdfplot(X) parses it to the vector and 
% displays CDF of all values.
%
% EXAMPLE:
% figure;
% cdfplot(randn(1,100));
% hold on;
% cdfplot(-log(1-rand(1,100)));
% cdfplot(sqrt(randn(1,100).^2 + randn(1,100).^2))
% legend('Normal(0,1) CDF', 'Exponential(1) CDF', 'Rayleigh(1) CDF', 4)

% Version 1.0
% Alex Podgaetsky, September 2003
% alex@wavion.co.il
%
% Revisions:
%       Version 1.0 -   initial version

if(exist('colour') == 0)
  colour = 'b';
end

if(exist('LogScale') == 0)
  LogScale = 0;
end

tmp = sort(reshape(X,prod(size(X)),1));
Xplot = reshape([tmp tmp].',2*length(tmp),1);

tmp = [1:length(X)].'/length(X);
Yplot = reshape([tmp tmp].',2*length(tmp),1);
Yplot = [0; Yplot(1:(end-1))];

figure(gcf);
if(LogScale == 1)
  hp = semilogy(Xplot, 1-Yplot,colour);
else
  hp = plot(Xplot, Yplot,colour);
end  

%ColOrd = get(gca, 'ColorOrder'); 
%ord = mod(length(get(gca,'Children')), size(ColOrd,1)); 
%set(hp, 'Color', ColOrd((ord==0) + (ord>0)*ord, :));

grid on;

