Same script in a path folder and the current folder. Which takes priority? (2024a, Ubuntu)

25 views (last 30 days)
I have an .m file (class) on a folder which was added to the matlab path. On a separate folder, I have another .m file with the same class but I am making some changes and tests to it. Hence the matlab woking folder is the second one.
In windows or macosx, the priority is for the local folder. So when I try to run static methods in my class, it will run the methods from the .m file in the local folder. However, in linux (Ubuntu), the priority is given to the .m file in the matlab path and I am unable to test my newly changed script.
Is there a way to have the behavior in linux match the behavior in windows or macosx?
Thanks in advance for any assistance.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Dec 2024 at 8:12
3. Nested functions within the current function
4. Local functions within the current file
6. Private functions
7. Object functions. An object function accepts a particular class of object in its input argument list. When there are multiple object functions with the same name, MATLAB checks the classes of the input arguments to determine which function to use.
8. Class constructors in @-folders
10. Functions in the current folder
11. Functions elsewhere on the path, in order of appearance
Now, static methods are not object functions (I think), so we need to ask whether these classes are defined in an @ folder or not; if so then that @ folder has priority. If not, then "functions in current folder" has priority over "functions elsewhere on the path"
... on the other hand, the bit about "when there are multiple object functions with the same name" could be construed as implying that if the method name is unique that input arguments are not checked, in which case possibly uniquely-named static functions are classed as object functions ?
In no case should the function on the path (that is not a @ directory) get priority over the local folder.
However... if you happen to load the class on the path, and then cd to a different directory that defines the same class, it is possible that the old class definition will be retained until you "clear classes" or "clear" the specific class.
  3 Comments
Walter Roberson
Walter Roberson on 30 Dec 2024 at 5:43

Is it only the static methods that is the problem or is it also the non-static methods?

ルーベン ルイス
ルーベン ルイス ongeveer 21 uur ago
Edited: ルーベン ルイス ongeveer 21 uur ago
Its the same. However, I think that there is more to the problem than simply Matlab. I think that I have a bit of a mess in terms of path-related environmental variables. In this sense, it may be that I raised the question in the wrong forum. I guess I need to re-test in a clean install.

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!