Error 'Matrix dimensions must agree' when using nanmean

1 visualización (últimos 30 días)
Colin Raymond
Colin Raymond el 20 de Jun. de 2020
Respondida: Colin Raymond el 20 de Jun. de 2020
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().

Respuesta aceptada

Colin Raymond
Colin Raymond el 20 de Jun. de 2020
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.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by