Files added to path won't run unless I rename them first.
조회 수: 65 (최근 30일)
이전 댓글 표시
I've been working with matlab for a little over a year now but towards the end of 2022 I found a issue where I would create a new script and add it to a folder that was already added to the path, but when I try to run it it says it's not in the path. However, once I rename the files then it seems to have no issue.
This is currently not a big issue and I hope it never will be but I am confused and it is a quality of life issue that I would like to fix.
댓글 수: 2
Dr. JANAK TRIVEDI
2023년 1월 31일
This issue could be due to the way MATLAB caches the list of functions in the path. When you add a new file to a folder that is already on the path, MATLAB may not immediately detect the change. To resolve this issue, you can use the rehash command to clear the cache and update the list of functions in the path.
Try running the following command in the MATLAB Command Window:
rehash
채택된 답변
John D'Errico
2023년 2월 5일
편집: John D'Errico
2023년 2월 5일
Never use the directory structure that comes with MATLAB to store your own files. Why not?
MATLAB caches those directories at startup. That means it will not see any changes made to your files. Of course, when you change the file, MATLAB will not know that, because it is still using the cached version.
Can you force MATLAB to see the change? Well, yes. You can issue a rehash command, forcing MATLAB to redo the cache on all of its files. Is that a good idea? Not really. It takes time. It forces you to remember to rehash the cache every time you make a minor change.
Instead, use your own directories to store your own m-files. This is a good idea anyway, since if you download a new release of MATLAB, then your files will no longer be found. All you need to do then is make sure you add your directory to the search path, and then save the path.
help pathtool
추가 답변 (1개)
Walter Roberson
2023년 1월 31일
How are you creating the new script?
If you are creating it outside of MATLAB then check Preferences -> Editor/Debugger -> Automatic file changes -> Reload unedited files that have been externally modified
If there is an existing handle to a function in the old file, then you need to "clear" and the name of the file, such as
clear MyFunction
if you modified MyFunction.m
댓글 수: 5
Stephen23
2023년 2월 5일
"I'm not exactly sure what that means but my guess to that question would be, MATLAB/bin/Matlab Programs."
You don't know where you are saving files? That must make working on a computer very difficult.
Why why why why why are you saving files into what appears to be the installation folder of an application?
Walter Roberson
2023년 2월 5일
MATLAB always assumes that anyone who adds new code inside of one of the installation directories will use rehash to inform it about the change.
This is in contrast to the other directories on the path, including the user's current directory: it continually scans those to see if new files have appeared and if so whether an old function needs to be removed from memory in order to use the new function.
Please have a look at userpath
참고 항목
카테고리
Help Center 및 File Exchange에서 Search Path에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!