function m = tsnanmean(x)

% Finds mean after excluding NaNs

%% If x is a vector m must -> scalar
if min(size(x))==1
    x = x(:);
end

m = NaN*ones([1 size(x,2)]);
for k=1:size(x,2)
    I = find(~isnan(x(:,k)));
    if ~isempty(I)
        m(k) = mean(x(I,k));
    end
end

    