Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "shadows it in the MATLAB path" mean? How to do it in a file?

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?

like image 212
hhh Avatar asked Apr 11 '13 02:04

hhh


1 Answers

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).

like image 169
Florian Brucker Avatar answered Oct 04 '22 19:10

Florian Brucker