MATLAB: Mean() is giving me an error, when when I use the test code Matlab suggests

errorMATLABmean function

Hi,
I am unable to reproduce the code given on the help page for the mean() function, https://www.mathworks.com/help/matlab/ref/mean.html
Here is the code I'm trying to run (I have version R2018a installed)
A(:,:,1) = [2 4; -2 1];
A(:,:,2) = [9 13; -5 7];
A(:,:,3) = [4 4; 8 -3];
M1 = mean(A,[1 2])
I keep getting the error:
Error using sum
Dimension argument must be a positive integer scalar within indexing range.
Error in mean (line 116)
y = sum(x, dim, flag) ./ size(x,dim);
I'm not sure why this is happening since this is the code given by the Matlab people, so it should work. Could someone help me with this please? Thanks.

Best Answer

Hi,
if you work with R2018a you should use the documentation from R2018a instead of R2018b. Work through the correct documentation and you will have success. Try:
M1 = mean(mean(A,1),2)
Best regards
Stephan