Home > atmlab > circular > circ_samplecdf.m

circ_samplecdf

PURPOSE ^

[phis, cdf, phiplot, cdfplot] = circ_samplecdf(thetas, resolution)

SYNOPSIS ^

function [phis, cdf, phiplot, cdfplot] = circ_samplecdf(thetas, resolution)

DESCRIPTION ^

 [phis, cdf, phiplot, cdfplot] = circ_samplecdf(thetas, resolution)

   Helper function for circ_kuipertest.
   Evaluates CDF of sample in thetas.
 
 Input: 
   thetas      sample (in radians)
   resolution  resolution at which the cdf is evaluated

 Output:
   phis        angles at which CDF is evaluated
   cdf         CDF values at these angles
   phiplot     as phi, for plotting
   cdfplot     as cdf, for plotting
 

 Circular Statistics Toolbox for Matlab

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

circ_samplecdf.m

SOURCE CODE ^

0001 function [phis, cdf, phiplot, cdfplot] = circ_samplecdf(thetas, resolution)
0002 
0003 % [phis, cdf, phiplot, cdfplot] = circ_samplecdf(thetas, resolution)
0004 %
0005 %   Helper function for circ_kuipertest.
0006 %   Evaluates CDF of sample in thetas.
0007 %
0008 % Input:
0009 %   thetas      sample (in radians)
0010 %   resolution  resolution at which the cdf is evaluated
0011 %
0012 % Output:
0013 %   phis        angles at which CDF is evaluated
0014 %   cdf         CDF values at these angles
0015 %   phiplot     as phi, for plotting
0016 %   cdfplot     as cdf, for plotting
0017 %
0018 %
0019 % Circular Statistics Toolbox for Matlab
0020 
0021 % By Marc J. Velasco, 2009
0022 % velasco@ccs.fau.edu
0023 
0024 if nargin < 2
0025     resolution = 100;
0026 end
0027 
0028 phis = 0;
0029 cdf = zeros(1, length(phis));
0030 
0031 phis = linspace(0,2*pi,resolution+1);
0032 phis = phis(1:end-1);
0033 
0034 % ensure all points in thetas are on interval [0, 2pi)
0035 x = thetas(thetas<0);
0036 thetas(thetas<0) = (2*pi-abs(x));
0037 
0038 % compute cdf
0039 thetas = sort(thetas); 
0040 dprob = 1/length(thetas); %incremental change in probability
0041 cumprob = 0; %cumultive probability so far
0042 
0043 % for a little bit, we'll add on 2pi to the end of phis
0044 phis = [phis 2*pi];
0045 
0046 for j=1:resolution
0047     minang = phis(j);
0048     maxang = phis(j+1);
0049     currcount = sum(thetas >= minang & thetas < maxang);
0050     cdf(j) = cumprob + dprob*currcount;
0051     cumprob = cdf(j);
0052 end
0053 
0054 phis = phis(1:end-1);
0055 
0056 % for each point in x, duplicate it with the preceding value in y
0057 phis2 = phis;
0058 cdf2 = [0 cdf(1:end-1)];
0059 
0060 cdfplottable = [];
0061 phisplottable = [];
0062 
0063 for j=1:length(phis);
0064    phisplottable = [phisplottable phis(j) phis2(j)]; %#ok<AGROW>
0065    cdfplottable = [cdfplottable cdf2(j) cdf(j)]; %#ok<AGROW>
0066 end
0067 
0068 phiplot = [phisplottable 2*pi];
0069 cdfplot = [cdfplottable 1];
0070 
0071 
0072 
0073 
0074

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005