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?
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:
+
at the beginning of its name. 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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With