MATLAB: Call function by path or namespace

function handleMATLABname clashnamespacepath

I have a package that was given to me that has some functions that have the same name as built in MATLAB functions, preventing me from calling the built in functions. I can image a similar situation where I have been given several packages with functions of the same name. Is there some way to call a function by path (or specify which function I want), or to specify a name space? I did find this similar question, where the suggested solution is to rename the functions, but logistically that can be difficult for packages I don’t control.

Best Answer

That's a good question. These two Matlab blogs
touch upon the topic. If nothing else they suggest that there is a real problem that lacks a good and simple solution.
You write "packages", but that word is already taken by Matlab, see Packages Create Namespaces.
"rename the functions, but logistically that can be difficult for packages I don’t control" indeed and when a new version of the package appears ... .
I have a suggestion that's workable in some cases
  • the package has a simple folder structure; not a lot of nested subfolders
  • the name collisions are caused by ordinary functions; not classes or package folders
  • the package shall permanently be on the Matlab search path
Move the functions that cause collosions to new or existing private folders. Something like
stat_package
code
...
+package_folder
private
private
mean
sum
It might be necessary to put copies of the a function that cause collosion in more than one private folder.