MATLAB Answers

0

Matlab Crushes when new .m file is added

Stelios Fanourakis さんによって質問されました 2019 年 6 月 16 日
最新アクティビティ John D'Errico
さんによって 編集されました 2019 年 6 月 16 日
Whenever I add a new .m file in the current folder, Matlab doesn't automatically recognize it and it prompts me to either change folder or add to path and then it just comes the error " Undefined Function" although the function exists at the working folder.
I have to shut down Matlab and reboot it in order to recognize it.
Any ideas why is this happening? Thanks

  0 件のコメント

サインイン to comment.

2 件の回答

John D'Errico
回答者: John D'Errico
2019 年 6 月 16 日
編集済み: John D'Errico
2019 年 6 月 16 日
 採用された回答

This is not a crash, nor even a crush. It is just that MATLAB caches the files in the MATLAB directories. It does this to enhance speed, pre-processing those files when it starts up. Therefore MATLAB does not watch those directories, not expecting any changes in them. This is why things "work" again for you when you restart, because MATLAB cached your changed files.
That means the solution is that you should NOT be using those directories! Do NOT save your files into the supplied directories. Instead, add your own directories to the search path. You can save files to your own directories with no problem at all.

  0 件のコメント

サインイン to comment.


Walter Roberson
回答者: Walter Roberson
2019 年 6 月 16 日

Sometimes MATLAB can get confused and you need to rehash. This can happen in various ways, including if a file that is not on the current path is modified, such as if you are cd'ing back and forth between directories.
If you are adding files to directories that are underneath the MATLAB installation (not a good idea) then rehash toolboxcache
In some cases involving network drives, MATLAB might not get notified when a file is updated, and you might need to rehash
If you are modifying a .m file which has been invoked in the current session, then MATLAB will not always notice the change, and you might need to clear the function name.

  0 件のコメント

サインイン to comment.



Translated by