MATLAB Answers

1

Undefined function error is very slow to occur

Asked by MathWorks Support Team on 3 Apr 2018
Latest activity Commented on by Adam Danz
on 14 Oct 2019 at 18:09
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:
>> fg
Undefined function or variable 'fg'.
If I turn off internet access, the delay in producing the message does not occur.

1 Answer

Answer by MathWorks Support Team on 8 Oct 2018
 Accepted Answer

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 = {''}

  4 Comments

Show 1 older comment
This is among the stupider "features" of matlab that has ever wasted my time. Why are you even searching for things using my history if they are not on my path? And if you are going to do something of such questionable value anyway, how could you implement it in a way that would destroy the user experience because someone switched to a network directory once in order to check something in matlab. For shame! Now at least I'll know when I have foolishly changed to a network directory in matlab and then I get this problem again, I'll remember what to google for to fix it. But really, this is my new job, working around Matlab "features"???
Dear Adam,
Your function restored my sanity, which had no backup. Thanks. And let me second Michael's sentiments.
Nils Olav
Adam Danz
on 14 Oct 2019 at 18:09
Thanks for the feedback, Nils. Feel free to support the function by rating it and leaving a comment here:

Sign in to comment.