function x = mynanmean(x,dim)

if dim > ndims(x)
    return
end
index = ~isnan(x);
n = sum(index,dim);
x(~index) = 0;
index = n > 0;
x = sum(x,dim);
x(index) = x(index) ./ n(index);
x(~index) = NaN;

end