Error 'Matrix dimensions must agree' when using nanmean

1 次查看(过去 30 天)
I'm on Mac 10.14.6 and Matlab R2019a. Nanmean and mean have always worked as expected, but suddenly they have begun throwing 'matrix dimensions must agree' errors for any and all inputs (for mean, this is only when using the 'omitnan' option). This happens even on simple 1D arrays, such as
nanmean([5;2;6;NaN;7])
The error is:
Matrix dimensions must agree.
Error in mean (line 105)
elseif any(opt=='aAgGhH')
Error in nanmean (line 22)
y = mean(varargin{:},'omitnan');
I haven't updated Matlab recently, or changed the environment (at least to my knowledge). Any idea what could be going on?
Interestingly
sum([5;2;6;NaN;7],'omitnan')/5
returns the expected result of 4, however of course this is not nearly as elegant as nanmean().

采纳的回答

Colin Raymond
Colin Raymond 2020-6-20
I discovered that the problem was a conflict between the outdated NaN package (which includes subfunctions titled nanmean.m and mean.m) and the preinstalled mean.m. Deleting the NaN package and using mean(x,'omitnan') now solves the issue.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by