matlabpath - order not respected?

2 次查看(过去 30 天)
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