MATLAB: Is there a way to have GEOMEAN skip values which are NaN

Statistics and Machine Learning Toolbox

I would like to use GEOMEAN on my dataset, but it has some values that are NaN.
I would like GEOMEAN to skip these values when it calculates the mean.

Best Answer

GEOMEAN cannot calculate the mean of a data set if it contains NaN values.
The following example code demonstrates how to remove NaN values from a dataset:
y = [ 1 NaN 2 3 4 NaN 5 6 7 NaN 8 9 10];
s = isnan(y);
y_mean = geomean(y(~s));
The same solution holds for a matrix 'y':
y = magic(4);
y([3 13 1 2]) = NaN;
s = isnan(y);
y_mean = geomean(y(~s));