How can one switch between locations of same namespace in one file system?

3 ビュー (過去 30 日間)
Ursina
Ursina 2025 年 6 月 12 日
コメント済み: Ursina 2025 年 6 月 16 日
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
  1. How can I choose between the two?
  2. 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

採用された回答

Benjamin Kraus
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
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.
Ursina
Ursina 2025 年 6 月 16 日
Thanks :)
I was not aware of the rehash function and it did the trick.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by