Which file Matlab selects if two different files with the same name are put under two folders, which are both added via addpath?
46 次查看(过去 30 天)
显示 更早的评论
Hi,
I have two functions with the same name. The contents of the functions are different although they share the same type of input and output. I put two functions (.m files) in 2 different folders and I add to Matlab path by calling addpath(genpath(folder_location)).
If I call this function, how does Matlab determine which m file to call? It seems to me that different Matlab versions handle differently. However, the way Matlab does is also not very clear. I am looking for the information for 2015a and 2017a.
Thanks,
2 个评论
Walter Roberson
2020-7-2
A far as I recall, R2015a and R2017a were both the same for .m files that are not part of classes and not import'd and not in + directories or 'private' directories. In both cases, the current directory would be searched first, and then the path would be searched in path order. Which is why addpath has specific -BEGIN and -END options, to permit you to tweak the order. (addpath defaults to adding at the beginning of the path.)
采纳的回答
Monisha Nalluru
2020-7-8
This is a known issue with addpath function in MATLAB R2017a and R2017b. This got fixed in R2018a. It is recommended to update the MATLAB version.
As a workaround for this issue is to remove the path and then add. This results in adding the path at top.
addpath(genpath('subfolder1'))
addpath(genpath('subfolder2'))
% Perform the required operations
% You can use restoredefaultpath command to set the path to default
rmpath('subfolder1')
addpath('subfolder1') % This will add the path on top again
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!