Problem with mean function

2 views (last 30 days)
Nina Schuback
Nina Schuback on 20 Jul 2017
Commented: carsten on 18 Jul 2018
If I try to calculate a simple mean say A=[1,2,3]; M=mean(A) I get an error message saying 'Undefined function 'mean' for input arguments of type 'double' I checked if I have overwritten mean with which mean -all and get the following answer:
C:\Program Files\MATLAB\R2016A\Research\toolbox\matlab\timefun\@duration\mean.m % duration method
C:\Program Files\MATLAB\R2016A\Research\toolbox\matlab\timefun\@datetime\mean.m % datetime method
C:\Program Files\MATLAB\R2016A\Research\toolbox\distcomp\parallel\@codistributed\mean.m % codistributed method
C:\Program Files\MATLAB\R2016A\Research\toolbox\distcomp\gpu\@gpuArray\mean.m % gpuArray method
C:\Program Files\MATLAB\R2016A\Research\toolbox\stats\stats\@ProbDistUnivParam\mean.m % ProbDistUnivParam method
C:\Program Files\MATLAB\R2016A\Research\toolbox\matlab\timeseries\@timeseries\mean.m % timeseries method

Accepted Answer

John D'Errico
John D'Errico on 20 Jul 2017
What you are missing is this version of mean:
/Applications/MATLAB_R2017a.app/toolbox/matlab/datafun/mean.m
At least that is the search path to it on my mac. The path to that function on your system will be different, but you apparently lack a function called mean in the datafun directory.
So, possibly you have deleted mean from that directory. More likely, do you have the datafun directory on your path at all? I'll conjecture that you may have accidentally removed it from your search path.
So check your search path. Just type path at the command line.
path
Your search path should list a directory datafun, that should be here:
C:\Program Files\MATLAB\R2016A\Research\toolbox\matlab\datafun
  2 Comments
carsten
carsten on 18 Jul 2018
Hey there, I am facing the same problem as Nina described above:
>> A = [0 1 1; 2 3 2; 1 3 2; 4 2 2];
>> mean(A);
Undefined function 'mean' for input arguments of type 'double'.
Apparently the mean function of datafun can not be accessed
>> which mean -all
C:\Program Files\matlab_v86_r15b_x64\toolbox\matlab\timefun\@duration\mean.m % duration method
C:\Program Files\matlab_v86_r15b_x64\toolbox\matlab\timefun\@datetime\mean.m % datetime method
C:\Program Files\matlab_v86_r15b_x64\toolbox\distcomp\parallel\@codistributed\mean.m % codistributed method
C:\Program Files\matlab_v86_r15b_x64\toolbox\distcomp\gpu\@gpuArray\mean.m % gpuArray method
C:\Program Files\matlab_v86_r15b_x64\toolbox\stats\stats\@ProbDistUnivParam\mean.m % ProbDistUnivParam method
C:\Program Files\matlab_v86_r15b_x64\toolbox\matlab\timeseries\@timeseries\mean.m % timeseries method
even though the datafun directory is listed in the path.
>> path
MATLABPATH
U:\MATLAB
...
C:\Program Files\matlab_v86_r15b_x64\toolbox\matlab\codetools
C:\Program Files\matlab_v86_r15b_x64\toolbox\matlab\datafun
C:\Program Files\matlab_v86_r15b_x64\toolbox\matlab\datamanager
...
Things I have tried so far:
(1) Deinstalltion and new installation of MATLAB but the problem still exists.
(2) When I navigate into the the datafun directory and run the same commands as above the mean function runs smoothly, so the function itself seems to be fine.
(3) Checking the configuration on a different computer:
>> which mean -all
C:\Program Files\MATLAB_v86_r15b_x64\toolbox\matlab\datafun\mean.m
C:\Program Files\MATLAB_v86_r15b_x64\toolbox\matlab\timefun\@duration\mean.m % duration method
C:\Program Files\MATLAB_v86_r15b_x64\toolbox\matlab\timefun\@datetime\mean.m % datetime method
C:\Program Files\MATLAB_v86_r15b_x64\toolbox\distcomp\parallel\@codistributed\mean.m % codistributed method
C:\Program Files\MATLAB_v86_r15b_x64\toolbox\distcomp\gpu\@gpuArray\mean.m % gpuArray method
C:\Program Files\MATLAB_v86_r15b_x64\toolbox\stats\stats\@ProbDistUnivParam\mean.m % ProbDistUnivParam method
C:\Program Files\MATLAB_v86_r15b_x64\toolbox\matlab\timeseries\@timeseries\mean.m % timeseries method
So the first line with the datafun entry is missing in my configuration.
How can I fix this problem?
@Nina: Could you please describe how you fixed it?

Sign in to comment.

More Answers (1)

RobF
RobF on 18 Jul 2018
Two commands that might always help when having path issues are the following:
>> restoredefaultpath
and
>> rehash
respectively
>> rehash path
>> rehash toolbox
>> rehash toolboxcache
Just enter them at your Matlab command prompt and check, if the functions are now available. More information:
>> doc restoredefaultpath
>> doc rehash
  1 Comment
carsten
carsten on 18 Jul 2018
The command
>> rehash toolbox
worked for me. Many thanks!!!

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!