Error 'Matrix dimensions must agree' when using nanmean

조회 수: 1 (최근 30일)
Colin Raymond
Colin Raymond 2020년 6월 20일
답변: Colin Raymond 2020년 6월 20일
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