Documentation of corr_nan


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


Function Synopsis

c = covar_nan(mat1, mat2);

Help text


  function c = covar_nan ( mat1 , mat2 ) ;

  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.

Cross-Reference Information

This function calls

Listing of function corr_nan

function c = covar_nan(mat1, mat2);

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);

kp1 = cell(1, n1);
kp2 = cell(1, n2);
for i = 1:n1;
  kp1{i} = find(~isnan(mat1(:,i)));
end
for j = 1:n2;
  kp2{j} = find(~isnan(mat2(:,j)));
end

c = NaN * ones(n1, n2);

for i = 1:n1;
  for j = 1:n2;
    kp  = intersect(kp1{i}, kp2{j});
    if length(kp)>1
      tem1 = standardize(mat1(kp,i));
      tem2 = standardize(mat2(kp,j));
      c(i,j) = tem1' * tem2 / (length(kp)-1);
    end
  end
end