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.
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().
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!