MATLAB: How to find mean with nan

mean nanStatistics and Machine Learning Toolbox

Hi!
I want to find mean with nan values and with different step. My script is:
RowDivision=[1,46,172,305,472,618,714,784,920];
nElement=diff(RowDivision); % step
meanG=cellfun(@mean,(mat2cell(G,nElement,ones(size(G,2),1)))); %mean
but if i have one only nan value i.e. from 1 to 46 the mean is nan. How can I ignore the nan? Thank you!

Best Answer

a=[1 2 nan 3 nan 10]
nanmean(a)
%or
mean(a(~isnan(a)))