matlabpath - order not respected?
4 次查看(过去 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)
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!