function  [m] = mean_nan(M)

% This routine will calculate the mean of the columns of matrix M,
% by-passing any NaNs found in the array

[I K] = size(M);

   for k = 1:K
        igd = find(~isnan(M(:,k)));
        if (length(igd) > 0)
                m(k) = mean(M(igd,k));
        else
                m(k) = nan;
        end
   end
