如何告诉Matlab“重新加载”存在于我的路径中的文件夹中的函数?

huangapple go评论63阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月25日 01:40:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326143.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定