7

enter image description here

I need to do this always before running unitTester file. I cannot understand why this is required. What does this mean? And why is the "Add to Path > Selected Folders and Subfolders" not enough?

[Update] This here may be the problem. The kernel is programmed in different techniques where the file names are the same. I need to make sure only certain files are used in each case. Is the easiest way use here a package not to mess up namespaces?

hhh
  • 50,788
  • 62
  • 179
  • 282
  • Check [this](http://www.mathworks.se/matlabcentral/newsreader/view_thread/254911) and [this](http://compgroups.net/comp.soft-sys.matlab/files-shadowing-themselves-case-of-direc/866751) discussion. I have also encountered this error but I don't remember what I did to solve it. Maybe you can programatically change the path inside the code. Or check from which directory the file is running by typing `which` – Autonomous Apr 11 '13 at 03:20
  • Regarding your update: The error message is about the names of the test scripts which seem to be the same. So that is something you need to fix first. Afterwards you need to check whether your naming scheme for the kernels introduces similar problems. – Florian Brucker Apr 12 '13 at 06:15

3 Answers3

6

MATLAB searches for m-files on its search path, you can display it using the path command. If you have multiple m-files with the same basename (i.e. the part of the filename before the extension, excluding the directories) on the MATLAB path then MATLAB can only execute the one that comes first on the path.

You can use the addpath and rmpath functions to dynamically modify the path. For example, you could automatically add the relevant directories automatically in your test running script. Note that addpath adds the new path to the head of the path list, which makes sure that it takes precedence over the existing entries.

Another way to prevent name conflicts like these are packages.

EDIT: To convert a directory into a package, do the following:

  • Add a + at the beginning of its name.
  • Make sure you put the directory's parent onto the MATLAB path.
  • Update all calls to functions within the package by either prepending packagename. to them or by including the package contents before the calls (import packagename.*).

In general I'd prefer packages to dynamic path modifications, because they're easier to use. Note that you can nest packages (i.e. my_matlab_files/+mypkg/+nested/foo.m).

Florian Brucker
  • 9,621
  • 3
  • 48
  • 81
  • Can you show an example how to make the different kernels [here](http://i.stack.imgur.com/VKPjM.png) into packages? How this specific case would work with addpath/rmpath? Pros/cons? Listlist is a kernel and sct is a kernel. I am testing different implementations and I think it is a smart idea to separate their namespaces with a package, making things easier to use anyway, hopefully. The first idea sounds a bit like hxcking...but probably faster. – hhh Apr 11 '13 at 21:01
  • 3
    The path is not the only place where MATLAB searches for functions. Also, it may not be MATLAB's first choice. Particularly, any function that happens to be in your current working directory blocks out any function of the same name anywhere on the MATLAB path. For specifics, see http://www.mathworks.de/de/help/matlab/matlab_prog/function-precedence-order.html – Alex Apr 12 '13 at 08:33
0

I encountered the same problem on OS X 10.10.3 with Matlab r2015a.

I had my files in ~/electrochemistry/Matlab/

Somehow renaming the last folder to lowercase resolved the problem. While troubleshooting I noticed Matlab was looking in ~/electrochemistry/matlab/, but couldn't find what it was looking for (i.e. my .m-file I was running)

So now I'm working in ~/electrochemistry/matlab/ and the problem is solved

Lucademicus
  • 383
  • 3
  • 9
0

Chane you source code name because it's name is the same of Matlab's source codes