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

3 views (last 30 days)
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.
  5 Comments

Sign in to comment.

Accepted Answer

Stephan
Stephan on 11 Feb 2019
Edited: Stephan on 11 Feb 2019
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
  1 Comment
rpinto73
rpinto73 on 11 Feb 2019
Hi Stephan,
Thank you so much for your answer and for including the link to the R2018a documentation - I didn't realize the functionality of mean() had changed from 2018a to 2018b, and was not sure how to access that 2018a documentation that Stephen mentioned in his comment.
Thanks again,
Rebecca

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!