Documentation of covar_nan3


Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)


Function Synopsis

[c, nsum2] = covar_nan(mat1, mat2, tol, show);

Help text


  function c = covar_nan ( mat1 , mat2 , tol, show ) ;

  This function computes the covariance matrix between
  mat1 and mat2, which may contain NaNs.  Elements of
  either matrix that have NaNs are ignored.

  It is assumed that the covariance will be taken along 
  the column dimension of mat1 and mat2.

  tol is the minimum number of simultaneous observations
  required in order to return a covariance for any
  index.  Default, tol = 2;

  show = 'show', 'noshow', or 1, 0, respectively.


Cross-Reference Information

This function calls This function is called by

Listing of function covar_nan3

function [c, nsum2] = covar_nan(mat1, mat2, tol, show);

if nargin < 3; tol = 2; end;

if nargin < 4; show = 0; end;
if isstr(show);
  show = strcmp(show, 'show');
end

if (size(mat1, 1) ~= size(mat2, 1));
  error('The number of columns of mat1 and mat2 must be equal');
end

[m1, n1] = size(mat1);
[m2, n2] = size(mat2);

if show; disp(['Number of iterations:  ' num2str(n1)]); end;

c = repmat(NaN, [n1, n2]);
nsum2 = repmat(NaN, [n1, n2]);
for i = 1:n1; 
  if show; 
    disp(['Iteration ' num2str(i) ' of ' num2str(n1)]); 
  end;
  for j = 1:n2;
    [sx, nsum] = sum2(mat1(:,i).*mat2(:,j));
    if nsum >= tol;
      c(i,j) = sx/(nsum-1);
      nsum2(i,j) = nsum;
    end
  end
end