Hi There,
I know its a little late, but I've had the same need for nanmean and nanstd, and when I stumbled across this I noticed that your function example will not provided the same answer as matlab. For example,
x= [1 2 NaN]
will produce the answer of 1.5 in matlab, but 2/3 using your function as it seems to produce the average number of values that are NaN.
I've written a nanmean and a nanstd function based off of some code I found on github for nansum. I have not optimized it for performance, but I wanted it to be able to handle arrays of various sizes.