Undefined function 'workspacefunc' — How to change search path back after accidentally changing it

I couldn't remember the function to check if a directory exists so I typed the following, and then accepted the suggested correction:
>> ispath('plots')
Unrecognized function or variable 'ispath'.
Did you mean:
>> path('plots')
Warning: Name is nonexistent or not a directory: /Users/billtubbs/gel-2005/notes/10/plots
> In path (line 34)
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
com.mathworks.jmi.MatlabException: Method 'workspaceUpdated' is not defined for class 'internal.matlab.variableeditor.MLNamedVariableObserver' or is removed from MATLAB's search path.
Now I get these errors whatever command I type (including path). I can't even quit MATLAB.
How do I recover from this situation?
Ideally I would like to restore whatever paths I had set up before typing the above command.

10 Comments

Thanks, this answer is interesting but not sure it solves my problem. The problem is not that my pathdef.m file has the wrong permissions or is corrupted. Also, I am unable to execute any commands at the moment so it's hard to follow any of the suggested remedies like restoredefaultpath.
I'm not actually sure where my pathdef.m file currently is or wether it exists. I tried typing cd $MATLABROOT in the terminal and it takes me to my home folder (/Users/billtubbs). There is no /toolbox/local/pathdef.m there.
Maybe I should "force-quit" MATLAB and restart? (I wanted to see if I could recover the previous path before doing this in case it is lost).
Okay, I found it. It's not at $MATLABROOT/toolbox/local/ it's in /Applications/MATLAB_R2019b.app/toolbox/local. So now I found it, how do I tell MATLAB where it is?
matlabroot is /Applications/MATLAB_R2019b.app and prefdir is ~/Library/Application Support/MathWorks/MATLAB/R2019b
I was referring to the filesystem environment variable $MATLABROOT mentioned in the suggested link above not the MATLAB variable matlabroot in the MATLAB environment. Incidentally, $MATLABPREFDIR and $MATLABROOT both point to the same place in my case but it is not the ~/Library/Application Support/MathWorks/MATLAB/R2019b directory.
MATLABROOT is not an actual environment variable in anything I have seen. It is not even defined by MATLAB when you
! printenv
It is standing in for the location of the installation directory.
Maybe I am mistaken. It's mentioned by MathWorks Support Team in the link above as a possible remedy:
sudo chmod 777 $MATLABROOT/toolbox/local/pathdef.m
Anyway, it doesn't work ("No such file or directory") as you suggest. I commented on the post to that effect.
The environment variable MATLABROOT is not expected to exist; where the documentation refers to $MATLABROOT it is described as being the MATLAB installation directory. It is an abbreviation for writing in "MATLAB Installation directory path goes here".
It can be misleading to people who are accustomed to actual environment variables.
MATLAB will not pay any attention to an environment variable MATLABROOT when it is executing; MATLAB constructs its notion of matlabroot() based upon the location of the MATLAB executable.

Sign in to comment.

 Accepted Answer

In the end I simply force-quitted MATLAB and restarted it and it works as normal again.
(Remember to save your work first).

Categories

Products

Release

R2019b

Tags

Community Treasure Hunt

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

Start Hunting!