Matlab keeps executing functions from the wrong file even though the current folder is set correctly. What's going on?

I have two folders with similar Matlab scripts that have the same name. I often have to hop back and forth in these folders. I always set the current folder (Home > Set Path) to the folder I am accessing. However, whenever I run a script in that folder, sometimes the functions being called are functions belonging to the folder I last used. I know this because I get an error telling me its running the function file in the wrong folder (I can see the function arguments in the error message). Any suggestions? I am happy to share any code, but I do not think that is neccessary.

3 件のコメント

I took the function being called in the incorrect folder and made a copy of it in my current folder. This fixed the problem but in a sketchy way. Is there a better way to go about this? I am guessing there is a good reason Matlab does it this way.
Stephen23
Stephen23 2019 年 7 月 23 日
編集済み: Stephen23 2019 年 7 月 24 日
" I always set the current folder (Home > Set Path) ..."
This might be the problem. The current folder does not require you to set anything: it is always simply the folder that you have cd-ed to, or browsed to, or whatever method you prefer to use... by default it is the MATLAB startup directory:
The current directory is searched before the folders listed in the Search Path, but this does not require that you set anything... in fact doing so is likely to cause exactly the kind of problems that you describe:
Thank you. The Cd method worked. I thoought the directory set up basically meant that matlab will search for the functions in the topmost folders first until it finds one with the matching name.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2019a

質問済み:

2019 年 7 月 23 日

コメント済み:

2019 年 7 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by