Error when using mean in matlab 2015

5 views (last 30 days)
I've been trying to use mean(A,2) for a 480 by 10 matrix. It should return a 480 by 1 array but instead returns a 480 by 10 matrix.
Flipping A and using mean(A) results in the following error
"Error using mean (line 3)
Not enough input arguments."
Thought I had a screwed up matrix first but then I tried
A=magic(5)
M=mean(A)
Which resulted in the same error. I can't continue with my code without sorting this out so does anyone know what might have caused this and how to fix?
Thanks in advance
  1 Comment
Stephen23
Stephen23 on 1 Nov 2015
You have shadowed the built-in mean function by defining a function or variable with the same name. This is a exactly the reason why you should never use the names of any built-in function for your own variable/function names. Before using any name, check if it already defined using which, and certainly avoid using size, length, mean, i, j, cat, cell, etc for your own varaibles.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Nov 2015
Use
which -all mean
You will find that the first one it locates is one of your own files instead of being in one of MATLAB's toolbox directories such as toolbox/matlab/datafun/mean.m . You need to rename or delete the mean.m that is coming from outside MATLAB (or at least remove the path to it.)

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!