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

조회 수: 3 (최근 30일)
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.

채택된 답변

Walter Roberson
Walter Roberson 2024년 12월 29일
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
Walter Roberson
Walter Roberson 2024년 12월 30일

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

ルーベン
ルーベン 2025년 1월 1일
편집: ルーベン 2025년 1월 1일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by