matlabpath - order not respected?
1 view (last 30 days)
Show older comments
Bjorn Gustavsson
on 5 Oct 2023
Commented: Bjorn Gustavsson
on 5 Oct 2023
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 Comments
Accepted Answer
Walter Roberson
on 5 Oct 2023
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!