Hi..
I want to find mean for array ingonring NaN. So i looked up in Matlab website and they suggest to use nanmean. I try the example but it returns '??? Undefined command/function 'nanmean''.
For Example:
X = magic(3);
X([1 6:9]) = repmat(NaN,1,5)
X =
NaN 1 NaN
3 5 NaN
4 NaN NaN
y = nanmean(X)
The result should be as following:
y = 3.5000 3.0000 NaN
But in my Matlab software, it returns ??? Undefined command/function 'nanmean'.
Is it because my Matlab version is 7.0.1?
Im new to Matlab. Thanks in advance for your help.

 채택된 답변

Jan
Jan 2012년 3월 21일

1 개 추천

X = magic(3);
X([1 6:9]) = NaN; % faster than: repmat(NaN,1,5)
index = isnan(X);
Y = X;
Y(index) = 0;
n = sum(~index, 1);
n(n == 0) = NaN;
M = sum(Y, 1) ./ n;
See also: FEX: NaN suite.

추가 답변 (1개)

Wayne King
Wayne King 2012년 3월 21일

2 개 추천

nanmean was available in version 7.0.1 but you have to have the Statistics Toolbox. Do you have the Statistics Toolbox in your installation, enter
>>ver
to see what you have installed.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2012년 3월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by