Default path issue- does path need to be set to the toolbox folder in Matlab on the Mac in Matlab 2022a?

When I launch Matlab 2022a, in the window on my Mac I see in red hundreds of lines like this
Warning: Name is nonexistent or not a directory: /Applications/MATLAB_R2022a.app/toolbox/matlab/external/engines/codegen/cpp
Warning: Name is nonexistent or not a directory: /Applications/MATLAB_R2022a.app/toolbox/matlab/editor_addons/compare/matlab
These are in my path. I do not see a way to add these toolbox files to the path (the folder is in the app and I can find it if I "Show package contents" in the app folder.
Does the path need to be set to these items? If I remove them from my path and they are needed I won't be able to add them back.

 Accepted Answer

Check if you have a redundant copy of pathdef.m:
which -all pathdef
If you see more than one entry (in particular, an entry that exists in a folder other than "/Applications/MATLAB_R2022a.app/toolbox/matlab/local/"), you probably want to rename or delete the second copy (which will be shadowing the official copy). If you delete it, check it first to see if you've added any personal directories. The only copy should be in the MATLAB installation folder (not a personal directory).
If you have a personal directories in a second copy of pathdef.m, my recommendation is to move them to startup.m. For example, you can create a startup.m file and add the following to that file:
addpath(<personal directory you want on the path>)
If that doesn't work, look into restoredefaultpath, but that should only be necessary if your built-in copy of pathdef.m has become corrupted.

4 Comments

This is what I see.
/Users/myname/Documents/MATLAB/pathdef.m
/Applications/MATLAB_R2022a.app/toolbox/local/pathdef.m % Shadowed
So I should rename the one in Douments since hte one you mentioned is being the one that is shadowed?
OR
If I decide to add a startup file, would I inlude the line
addpath( /Users/myname/Documents/MATLAB/)?
My guess is that /Users/myname/Documents/MATLAB/pathdef.m was created in an old copy of MATLAB and is incompatible with MATLAB R2022a, which is what is causing your issue.
  1. Start by renaming /Users/myname/Documents/MATLAB/pathdef.m to something other than pathdef.m. Once you've renamed the file, restart MATLAB and that should resvoled the issue you are having.
  2. Next decide whether there was anything in your old (now renamed) pathdef.m that you need to preserve. If not, you are done, you can stop here (step 5 is optional).
  3. If there is something in the renamed pathdef.m that you want to keep, then you should add it to a new file named /Users/myname/Documents/MATLAB/startup.m (i.e. put it in the folder with your errant/renamed pathdef.m file).
  4. Within startup.m, add an addpath entry for any directories you want to keep from your old pathdef.m.
  5. Optional: Once you know there is nothing left in your renamed pathdef.m that you need to save, you can delete the renamed file.
Note: You shouldn't modify/rename/delete the file /Applications/MATLAB_R2022a.app/toolbox/local/pathdef.m. All the steps above are about the files in /Users/myname/Documents/MATLAB/.
Example
Let's say the copy of pathdef.m in your Documents directory looked like this:
p = [...
%%% BEGIN ENTRIES %%%
'/Users/myname/Documents/MyMATLABStuff/', ...
'/Users/myname/Documents/DownloadedMATLABStuff/', ...
matlabroot,'/toolbox/matlab/addon_enable_disable_management/matlab:', ...
matlabroot,'/toolbox/matlab/addon_updates/matlab:', ...
matlabroot,'/toolbox/matlab/addons:', ...
matlabroot,'/toolbox/matlab/addons/cef:', ...
matlabroot,'/toolbox/matlab/addons/fileexchange:', ...
In that example, everything that starts with matlabroot can be ignored (they are included in the default pathdef.m). The first two entries are personal items. You can create a new file called startup.m that looks like this:
addpath('/Users/myname/Documents/DownloadedMATLABStuff/')
addpath('/Users/myname/Documents/MyMATLABStuff/')
When I try to remove those items and save the pathdef, I get the error I screenshotted in the attached file.
Is the startup.m a file or a folder?
When I rename the pathdef it doesn't add anything I need to the path. And I sitll can't use SETPATH to change it.
  • startup.m is a file. Creating a startup.m file is documented here startup.
  • Click "No" on the "Set Path" dialog. You do not want to save pathdef.m to a new location, that's how you got into this situation in the first place. That may work temporarily, but when you upgrade MATLAB you find yourself with a copy of pathdef.m that is incompatible with your new MATLAB.
  • Do not use the Path Tool (pathtool) or "Set Path" or savepath. Those tools try to modify the (write protected) pathdef.m that is located in your MATLAB installation, which you should never modify (which is why it is write protected). When that fails, it creates a copy of pathdef.m in your userpath. That second copy is what caused this issue.
Your goal is not to modify pathdef.m. Modifying pathdef.m will work as long as you never update MATLAB, but if you update MATLAB you either end up with a pathdef.m that is incompatible with the new MATLAB or you lose any customizations every time you update MATLAB.
My recommended solution avoids that issue.
  • Do not modify pathdef.m.
  • Instead you want to add any path customizations to startup.m.
  • Within startup.m you are going to use addpath to add new (personal) items to the path without modifying the entries that are already there.
  • When you update MATLAB, you will get a new pathdef.m with the MATLAB installation, then startup.m will run and add your personal entries to the path from the new MATLAB. This is a more sustainable solution than modifying pathdef.m.
  • This will also allow you to switch between versions of MATLAB (back and forth if you wanted) without issue.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!