英文:
How to tell Matlab to "reload" the functions that exist in a folder in my path?
问题
我把许多自制函数放在一个通用目录中,就像这样:\nU:\matlab\functions(U:是Windows 10中的映射网络驱动器)。\n\n在我的startup.m中,我将其添加到我的路径中:\n\naddpath('U:\matlab\functions');\n
\n\n我可以在该目录中无问题地访问函数,直到我在会话期间向该目录添加新函数。添加新函数后尝试使用它,Matlab就找不到它了。我尝试使用新函数,它会说\n\n未识别的函数或变量'newfunction'\n
\n\n或者我执行\n\nwhich newfunction\n
\n它会说\n\n'newfunction'未找到\n
\n我必须关闭并重新启动Matlab会话,才能使其找到我刚刚创建的新函数。有没有办法告诉Matlab在我的路径中包含的函数目录中“重新加载”它所看到的内容,而无需重新启动会话?\n\n我使用的是Matlab R2022a,但我在早期版本中也遇到过这种情况。
英文:
I keep many homemade functions in a common directory like this:
U:\matlab\functions
(U: is a mapped network drive in Windows 10).
In my startup.m I add it to my path:
addpath('U:\matlab\functions');
I can access functions in that directory with no problems until I add a new function in that directory during a session. After I add a new function and try to use it, Matlab doesn't find it. I try to use the new function and it says
Unrecognized function or variable 'newfunction'
Or I do a
which newfunction
and it says
'newfunction' not found
I have to close and restart the Matlab session to have it find the new function I just created. Is there any way to tell Matlab to "reload" what it sees in the functions directory that is included in my path without restarting my session?
I'm using Matlab R2022a, but I've seen this in earlier versions.
答案1
得分: 4
是的,您可以使用 rehash:
rehash 更新 MATLAB® 中未在 matlabroot 中的搜索路径上的已知文件和类的列表。它比较已加载函数的时间戳与磁盘上的时间戳。如果磁盘上的文件更新,则会清除已加载的函数。
英文:
Yes, you can use rehash:
> rehash updates the MATLAB® list of known files and classes for folders on the search path that are not in matlabroot. It compares the timestamps for loaded functions against their timestamps on disk. It clears loaded functions if the files on disk are newer.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论