Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)
[xy,ccuse,avl] = cov5(x,y)
For the 2x2 matrix, only returns a single value... function [xy,ccuse,avl] = cov5(x,y) COV2 Jim's "normalise by N" Covariance matrix of time series that include NaNs. ^^^^^^^^^^^^^^ COV2(X), if X is a vector, returns the variance. For matrices, where each row is an observation, and each column a variable, COV2(X) is the covariance matrix. DIAG(COV2(X)) is a vector of variances for each column, and SQRT(DIAG(COV2(X))) is a vector of standard deviations. COV2(X,Y) is COV([X Y]). See also COV, CORRCOEF, CORRCOEF2, STD. J. Little 5-5-86 Revised 6-9-88 LS Copyright (c) 1984-93 by The MathWorks, Inc. ***** REVISED BY JR, 27 Apr 1994 - normalises by n, not n-1 ***** REVISED by ID, 5 Oct 1995 - skips NaNs. XY is the covariance matrix and AVL is a row vector with the percentage of observations available in each column.
|This function calls||This function is called by|
function [xy,ccuse,avl] = cov5(x,y) [m,n] = size(x); if nargin > 1 [my,ny] = size(y); if m ~= my | n ~= ny error('X and Y must be the same size.'); end x = [x(:) y(:)]; elseif min(size(x)) == 1 x = x(:); end [m, n] = size(x); x = x - ones(m,1) * mean2(x); if m == 1 xy = 0; else for i=1:n, for j=i:n, use = find(~isnan(x(:,i))&~isnan(x(:,j))); avl(i,j) = length(use); avl(j,i) = avl(i,j); if avl(i,j) <= 1, xy(i,j) = NaN; else xy(i,j) = x(use,i)'*x(use,j)/avl(i,j); xy(j,i) = xy(i,j); end end end end % avl is fraction used to determine covariance avl = (avl/m)*100; % ccuse is the values used for the correlation coefficient if n==2 ccuse=find(~isnan(x(:,1))&~isnan(x(:,2))); end [mm,nn]=size(xy); if mm==2 xy=xy(1,2); end