This is a static copy of a profile report

Home

cov (12115 calls, 3.164 sec)
Generated 05-Nov-2014 07:53:52 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/datafun/cov.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
ml_bwmomentfunction6058
ml_parsecell>updates2subfunction6057
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
93
xc = bsxfun(@minus,x,sum(x,1)/...
121151.021 s32.3%
45
if ~iscovflag(flag)
121150.381 s12.0%
95
xy = (xc' * xc) / m;
121150.371 s11.7%
68
x = [x y];
121150.240 s7.6%
64
if length(x) ~= length(y), 
121150.110 s3.5%
All other lines  1.041 s32.9%
Totals  3.164 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
cov>iscovflagsubfunction121150.230 s7.3%
Self time (built-ins, overhead, etc.)  2.934 s92.7%
Totals  3.164 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in function100
Non-code lines (comments, blank lines)42
Code lines (lines that can run)58
Code lines that did run27
Code lines that did not run31
Coverage (did run/can run)46.55 %
Function listing
   time   calls  line
1 function xy = cov(x,varargin)
2 %COV Covariance matrix.
3 % COV(X), if X is a vector, returns the variance. For matrices,
4 % where each row is an observation, and each column a variable,
5 % COV(X) is the covariance matrix. DIAG(COV(X)) is a vector of
6 % variances for each column, and SQRT(DIAG(COV(X))) is a vector
7 % of standard deviations. COV(X,Y), where X and Y are matrices with
8 % the same number of elements, is equivalent to COV([X(:) Y(:)]).
9 %
10 % COV(X) or COV(X,Y) normalizes by (N-1) if N>1, where N is the number of
11 % observations. This makes COV(X) the best unbiased estimate of the
12 % covariance matrix if the observations are from a normal distribution.
13 % For N=1, COV normalizes by N.
14 %
15 % COV(X,1) or COV(X,Y,1) normalizes by N and produces the second
16 % moment matrix of the observations about their mean. COV(X,Y,0) is
17 % the same as COV(X,Y) and COV(X,0) is the same as COV(X).
18 %
19 % The mean is removed from each column before calculating the
20 % result.
21 %
22 % Class support for inputs X,Y:
23 % float: double, single
24 %
25 % See also CORRCOEF, VAR, STD, MEAN.
26
27 % Copyright 1984-2010 The MathWorks, Inc.
28 % $Revision: 5.16.4.10 $ $Date: 2010/08/23 23:07:32 $
29
0.03 12115 30 if nargin==0
31 error(message('MATLAB:cov:NotEnoughInputs'));
32 end
0.02 12115 33 if nargin>3
34 error(message('MATLAB:cov:TooManyInputs'));
35 end
0.04 12115 36 if ~ismatrix(x)
37 error(message('MATLAB:cov:InputDim'));
38 end
39
0.03 12115 40 nin = nargin;
41
42 % Check for cov(x,flag) or cov(x,y,flag)
0.01 12115 43 if nin==3
0.09 12115 44 flag = varargin{end};
0.38 12115 45 if ~iscovflag(flag)
46 error(message('MATLAB:cov:notScalarFlag'));
47 end
0.01 12115 48 nin = nin - 1;
49 elseif nin==2 && iscovflag(varargin{end})
50 flag = varargin{end};
51 nin = nin - 1;
52 else
53 flag = 0;
54 end
55
0.03 12115 56 scalarxy = false; % cov(scalar,scalar) is an ambiguous case
0.01 12115 57 if nin == 2
0.02 12115 58 y = varargin{1};
0.04 12115 59 if ~ismatrix(y)
60 error(message('MATLAB:cov:InputDim'));
61 end
0.06 12115 62 x = x(:);
0.06 12115 63 y = y(:);
0.11 12115 64 if length(x) ~= length(y),
65 error(message('MATLAB:cov:XYlengthMismatch'));
66 end
0.05 12115 67 scalarxy = isscalar(x) && isscalar(y);
0.24 12115 68 x = [x y];
0.03 12115 69 end
70
0.03 12115 71 if isvector(x) && ~scalarxy
72 x = x(:);
73 end
74
0.03 12115 75 [m,n] = size(x);
0.06 12115 76 if isempty(x);
77 if (m==0 && n==0)
78 xy = NaN(class(x));
79 else
80 xy = NaN(n,class(x));
81 end
82 return;
83 end
84
0.03 12115 85 if m == 1 % One observation
86
87 % For single data, unbiased estimate of the covariance matrix is not defined.
88 % Return the second moment matrix of the observations about their mean.
89 xy = zeros(n,class(x));
90
0.02 12115 91 else
92
1.02 12115 93 xc = bsxfun(@minus,x,sum(x,1)/m); % Remove mean
0.01 12115 94 if flag
0.37 12115 95 xy = (xc' * xc) / m;
96 else
97 xy = (xc' * xc) / (m-1);
98 end
99
0.10 12115 100 end

Other subfunctions in this file are not included in this listing.