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

43 views (last 30 days)
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

Benjamin Kraus
Benjamin Kraus on 30 Dec 2024 at 19:50
Edited: Benjamin Kraus on 30 Dec 2024 at 19:51
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
Coraline
Coraline on 31 Dec 2024 at 1:07
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.
Benjamin Kraus
Benjamin Kraus on 1 Jan 2025 at 13:13
  • 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

Find more on Search Path in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!