how to find mean with nan
조회 수: 12(최근 30일)
I want to find mean with nan values and with different step. My script is:
nElement=diff(RowDivision); % step
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!
Image Analyst 2014년 10월 10일
If you have the Stats toolbox, use nanmeans. If you don't, you can do it in two lines of code, one to find the nans and one to get the mean:
% Create sample data
% Make some nans
RowDivision(2) = nan;
RowDivision(4) = nan
% Find the nans
nanElements = isnan(RowDivision)
% Compute the mean with no nans being considered.
meanNoNans = mean(RowDivision(~nanElements))
Actually you can do that in one line of code if you want.