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 Center および File ExchangeFunction Creation についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by