Undefined function error is very slow to occur

3 次查看(过去 30 天)
Whenever I type or have a script/M-file with an undefined function or variable (usually through a typo), MATLAB takes about 40 seconds to return the 'Undefined function or variable' message. For example: 
ERROR: >> fg
Undefined function or variable 'fg'.
If I turn off internet access, the delay in producing the message does not occur. 

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2022-5-13
This is most likely due to having network locations on your MATLAB path. While connected to the internet, MATLAB searches through all of these paths before concluding that no such variable/function exists. When not connected to the internet, MATLAB is forced to ignore any network locations. To check this, you can restore the default MATLAB path. Please note that if you have custom paths that you would like to keep on your MATLAB path, you may want to back them up first. See this MATLAB Answers post for more details:
To restore the default MATLAB path, execute the following in the MATLAB Command Window and then restart MATLAB:
>> restoredefaultpath
>> rehash toolboxcache
>> savepath
If this does not correct the issue, then you may have some network locations in your history. You can clear your history by executing the following and then restarting MATLAB:
 
>> s = settings;
>> s.matlab.desktop.currentfolder.History.PersonalValue = {''}
You can also change the maximum size of your history, so that MATLAB will not store as many locations. To do this, execute the following code and restart MATLAB:
>> s = settings:
>> s.matlab.desktop.currentfolder.HistorySize.PersonalValue = 20; % you can adjust this value
  2 个评论
Adam Danz
Adam Danz 2018-4-22
编辑:Adam Danz 2019-8-25
Thanks, that also addresses the issue I posted on another thread last year. I'll update that thread with a link to this answer.
[UPDATE]
Since the problem can reoccur, I wrote a function that address disconnected network locations in the Matlab history. The function below creates a GUI that lists all network drives that appear in the Matlab history. The user can select any (or all) of the drives that they no longer have access to and it will remove those from history. The effect was immediate for me and I no longer had to deal with the wait time. Other options in the GUI allow the user to restore the history from a backup if needed. It's a pretty simple.
I'd be interested in knowing if this solves the problem for others, too.
Adam Danz
Adam Danz 2019-10-14
Thanks for the feedback, Nils. Feel free to support the function by rating it and leaving a comment here:

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by