Documentation of var_nan


Global Index (short | long) | Local contents | Local Index (short | long)


Function Synopsis

v = var_nan(mat1);

Help text


  function v = var_nan ( mat1 ) ;

  This function computes the variance of each column of
  mat1, which may contain NaNs.  Elements of mat1 that 
  are NaN's are ignored.

  It is assumed that the variance will be taken along 
  the column dimension of mat1.

Cross-Reference Information

This function calls This function is called by

Listing of function var_nan

function v = var_nan(mat1);

[m1, n1] = size(mat1);
v = NaN*ones(1, n1);

mat1 = mat1 - ones(m1, 1)*mean2(mat1);

for i = 1:n1;
  kp1 = find(~isnan(mat1(:,i)));
  if ~isempty(kp1);
    v(i) = mat1(kp1,i)'*mat1(kp1,i) / (length(kp1)-1);
  end
end