필터 지우기
필터 지우기

matlabpath - order not respected?

조회 수: 2 (최근 30일)
Bjorn Gustavsson
Bjorn Gustavsson 2023년 10월 5일
댓글: Bjorn Gustavsson 2023년 10월 5일
In one of the toolboxes I have downloaded there are some functions (erf, gamma) that are shading the corresponding built-in functions, even when I add that directory to the end of the matlab-path:
>> which gamma -all
built-in (/usr/local/MATLAB/R2020a/toolbox/matlab/specfun/@double/gamma) % double method
built-in (/usr/local/MATLAB/R2020a/toolbox/matlab/specfun/@single/gamma) % single method
/usr/local/MATLAB/R2020a/toolbox/symbolic/symbolic/@sym/gamma.m % sym method
/usr/local/MATLAB/R2020a/toolbox/parallel/parallel/@codistributed/gamma.m % codistributed method
/usr/local/MATLAB/R2020a/toolbox/parallel/gpu/@gpuArray/gamma.m % gpuArray method
>> addpath /home/bgu001/matlab/Local/Numerics/Polpack/ -end
>> which gamma -all
/home/bgu001/matlab/Local/Numerics/Polpack/gamma.m
built-in (/usr/local/MATLAB/R2020a/toolbox/matlab/specfun/@double/gamma) % double method
built-in (/usr/local/MATLAB/R2020a/toolbox/matlab/specfun/@single/gamma) % single method
/usr/local/MATLAB/R2020a/toolbox/symbolic/symbolic/@sym/gamma.m % sym method
/usr/local/MATLAB/R2020a/toolbox/parallel/parallel/@codistributed/gamma.m % codistributed method
/usr/local/MATLAB/R2020a/toolbox/parallel/gpu/@gpuArray/gamma.m % gpuArray method
>> rmpath('/home/bgu001/matlab/Local/Numerics/Polpack/')
>> which gamma -all
built-in (/usr/local/MATLAB/R2020a/toolbox/matlab/specfun/@double/gamma) % double method
built-in (/usr/local/MATLAB/R2020a/toolbox/matlab/specfun/@single/gamma) % single method
/usr/local/MATLAB/R2020a/toolbox/symbolic/symbolic/@sym/gamma.m % sym method
/usr/local/MATLAB/R2020a/toolbox/parallel/parallel/@codistributed/gamma.m % codistributed method
/usr/local/MATLAB/R2020a/toolbox/parallel/gpu/@gpuArray/gamma.m % gpuArray method
This is not what I have learnt to expect. Matlab should use the first function on the path with the matching name, shouldn't it? Is this something others have encountered? Is it a new behaviour? What can I have done to cause me this?
The versions this definitely appears on are R2020a and 2022b (Update 3)

채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 5일
Matlab should use the first function on the path with the matching name, shouldn't it?
All of those method that are listed are object functions, which are priority 7
Functions elsewhere on the path, in order of appearance are priority 11.
When you addpath that directory, the gamma there becomes the only regular function on the search path with name gamma . The other gamma are only invoked if one of the parameters is the correct data type -- and if the parameters are the correct datatype then those have higher priority than the function you added on the path.
Why does MATLAB list the path first before the methods? I do not know -- but that does not affect resolution priority. The path is not searched until after it is determined that the function call is not an object method for class of the parameters.
  댓글 수: 1
Bjorn Gustavsson
Bjorn Gustavsson 2023년 10월 5일
Thanks, that explains this.
For others that might stumble on this answer this might be a useful advice:
Run which with an input argument of the correct type:
which erf(pi) -all
For an explicitly correct and understandable listing, instead of
which erf -all

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by