nanmean giving nansum output
이전 댓글 표시
function 'nanmean' is behaving like nansum and I don't know why. the help command (image below) is also referencing nansum's functionality.
any ideas? i recently updated to 2022b..

채택된 답변
추가 답변 (1개)
function 'nanmean' is behaving like nansum
In what way? Example?
i recently updated to 2022b..
If so, why use nanmean at all? As the documentation told you, it's obsolete. Instead, use
Y=mean(X,dim,'omitnan')
댓글 수: 4
Ralph Andrews
2023년 2월 13일
Then wrap it in a shorter function...
>> nanavg([1,2,3, nan, nan])
ans =
2
function out=nanavg(varargin)
out=mean(varargin{:},'omitnan');
end
Or, abbreviate the flag:
x=[1,2,3, nan, nan];
mean(x,'o')
the cyclist
2023년 2월 13일
@Ralph Andrews, I would at least consider using the (officially recommended) syntax that @Matt J shared.
I don't know how experienced a user you are, but my perspective is that a little bit of extra typing is always worth some extra robustness and code clarity. (I would definitely not use 'o' instead of 'omitnan', though!)
At the very least, I would suggest reading the version history of nanmean, and understand the reasons that it is not recommended. (But, there are no plans to remove that function, so you are safe in that sense.)
Ralph Andrews
2023년 2월 13일
카테고리
도움말 센터 및 File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!