Undefined function 'geomean' for input arguments of type 'double' in Matlab 2020

조회 수: 5 (최근 30일)
Dear all,
I have a simple code containing "geomean" for a data with nan values. I tried this code:
geomean(X,'omitnan')
in Matlab 2022 and it runs well. But, when I tried in Matlab 2021, I got this message:
Undefined function 'geomean' for input arguments of type 'double'.
I also tried a classical way:
geomean(X(~isnan(X)));
And it gives me the same problem.
Any suggestion regarding this error?

채택된 답변

Steven Lord
Steven Lord 2023년 3월 4일
The geomean function is part of Statistics and Machine Learning Toolbox. Do you have this toolbox installed and licensed? You can check this by running the ver command and looking for a line starting with "Statistics and Machine Learning Toolbox" in the displayed output.
If that line does not exist you will need to install Statistics and Machine Learning Toolbox to use this function.

추가 답변 (2개)

Star Strider
Star Strider 2023년 3월 4일
An alternative is:
gm = @(x) prod(x)^(1/numel(x));
x = rand(1,100);
y1 = geomean(x)
y1 = 0.3765
y2 = gm(x)
y2 = 0.3765
.
  댓글 수: 11
Star Strider
Star Strider 2023년 3월 5일
I do not understand what you are doing.
Numeric functions will not usually work on non-numeric (such as string) data. These will not, because they are not designed to. I doubt that geomean is, either.
If you are getting the ‘Undefined function’ error, that means that ‘gm’ was not in your code before you called it. It is an anonymous function, so it must be close to the beginning of your code in order to use it later. It is not like a function file.
.
Walter Roberson
Walter Roberson 2023년 3월 5일
The anonymous function gm is not designed to be a complete drop-in replacement for all functionality of geomean. Star Strider and I made no attempt to handle omitnan or the dimension arguments, and did not pay attention to calculations on matrices.
We also were not telling you that gm or gmL were already available in your version of MATLAB: we were providing a quick fix.
If you need more functionality then you should define your own gm.m using the mathematical logic we show, but perhaps looping over each column removing nan values before doing the calculation.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2023년 3월 4일
it needs the Statistics and Machine Learning toolbox
  댓글 수: 2
Adi Purwandana
Adi Purwandana 2023년 3월 5일
I checked my my licenses, the toolbox has been installed on my 2022 academic license but not in my personal license (2021).
Walter Roberson
Walter Roberson 2023년 3월 5일
편집: Walter Roberson 2023년 3월 5일
The software needs to be licensed and installed on whatever MATLAB you are executing the code with.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by