How can one switch between locations of same namespace in one file system?
조회 수: 3 (최근 30일)
이전 댓글 표시
Kind reader,
I work with a namespace to structure function families. The development folder is a git checkout and I managed to write an installer for the namespace. So the relesed state of the namespace is in the Program Data folder and the path is added in Matlab.
Questions: As boths namespace folders path are now added to Matlab
- How can I choose between the two?
- How can I activated/deactivate one of them?
---------------------- File system depiction --------------------------------
- C:gitClone/+myNamespace -C:ProgramData/myNamespace
- /+awsomeFunctions - /+awsomeFunctions
- /+helpfulFunctions - /+helpfulFunctions
-----------------------------------------------------------------------------
As I provide a release of the namespace to co-workers I have to be able to check the installation on my development computer. I read about package creation in Matlab (mpmcreate - Create package - MATLAB) but that does not work for namespaces.
Every hint, comment, and thought about this issue is highly appreciated :)
Environement: Windows with Matlab 2024b
댓글 수: 0
채택된 답변
Benjamin Kraus
2025년 6월 12일
편집: Benjamin Kraus
2025년 6월 12일
If you have two folders on the path that both include the same namespace folders, their contents will be merged. If there are files in those folders with the same name (and namespace), the ones that were added to the path second will shadow the other versions.
Given that both folders are clones of each other (one is the development version and the other is the production version), I assume they will have almost the same files, in which case, whichever version was added to the path second will "win" and the other one will be ignored.
For development purposes, I suggest writing a script to switch between the two different versions by adding and removing one or the other from the path. You can use which to find which version is "active" or which -all to find all versions of your scripts that are available.
댓글 수: 6
Benjamin Kraus
2025년 6월 13일
Whatever path is added second will get precedance... so in your code above, you called addpath(devPath) second, so I would expect the "C:\svn\" path would get priority, which is what I'm seeing. If you swapped the order, I would expect the prodPath would take over for the devPath.
I did some quick testing: I created two folders called "Test1" and "Test2". Both had a function named "foobar.m". I ran the following:
addpath('Test1')
foobar % Test 1 version ran
addpath('Test2')
foobar % Test 2 version ran
addpath('Test1')
foobar % Test 1 version ran
addpath('Test2')
foobar % Test 2 version ran
This supports what I thought to be the expected behavior.
If you aren't seeing that, then you may need to run rehash to tell MATLAB to recognize the change in path. I'm not sure the exact criteria under which you would need to run rehash, but give that a shot and see if it helps.
Another thing to be wary of: If you use something like mlock or persistent, or if you have an instance of a class stored in a variable in your workspace, that can cause MATLAB to continue using the old definition even after you've switched the path.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!