How to use "savepath" for adding path to pathdef.m in Linux?

Hello All,
I am using MATLAB R2020a on Ubuntu 20.04.3 LTS. I have installed YALMIP and GUROBI, and I am using them on MATLAB.
The problem, however, is that I need to reintall these two whenever I open MATLAB.
When I use savepath command, I get the following error.
Warning: Unable to save path to file '/usr/local/MATLAB/R2020a/toolbox/local/pathdef.m'. You can save your path
to a different location by calling SAVEPATH with an input argument that specifies the full path. For MATLAB to
use that path in future sessions, save the path to 'pathdef.m' in your MATLAB startup folder.
> In savepath (line 176)
According to what I found online, I have copied and pasted the pathdef.m from the directory mentioned in the error message to another directory. Then, I used the savepath command with an arguement specifying the location of the pasted pathdef.m file to save the current path. This did not work.
Is there a permanent solution to this issue?
Any help is greatly appreciated!

4 Comments

This did not work.
So you do something like
savepath ~/Documents/MATLAB/pathdef.m
and then when you start up MATLAB, the new path is not taken into account? Is there an error message?
What shows up if you give the command
userpath()
Thank you for your reply!
Unfortunaly, doing what you suggested did not work.
1- I installed Yalmip again,
2- typed, savepath ~/Documents/MATLAB/pathdef.m,
3-started up Matlab again, and
4- got this:
>> yalmip
Unrecognized function or variable 'yalmip'.
>> userpath()
ans =
'/home/Nassim/Documents/MATLAB'
>>
If you compare the content of ~/Documents/MATLAB/pathdef.m from before you do the install, and then after you do the install and savepath, is there any difference ?
When I started MATLAB again, I checked and saw that the path is added to pathdef.m in ~/Document/MATLAB. Then, I checked if Yalmip is intalled or not. It was not installed.
The same thing happended when I copy pasted pathdef in another directory. The added directory for Yalmip was saved on pathdef.m, but Yalmip was not installed.

Sign in to comment.

Answers (1)

Hi Nasim,
I understand that you are unable to save the path and encounter a warning.
The MATLAB path is saved in the 'pathdef.m' file as suggested in the warning message you receive. Users who do not have administrative privileges are not able to write in this directory. This may be one of the reasons why you are unable to save the paths.
To work around this issue, you can save the ADDPATH command in "startup.m" in the current startup directory, if you have write permission to that directory. The startup directory can be modified by right-clicking on the MATLAB shortcut and clicking on "properties".
Or, you also can save your ADDPATH command in a .m file in their respective work directories and run it using startup options each time they start MATLAB. This can be done as follows:
1. You must save your ADDPATH command in a file, say (username)_path.m.
2. While starting MATLAB, you can start it up at the system prompt as follows:
matlab /r (username)_path
I hope this helps!

Categories

Products

Release

R2020a

Asked:

on 18 Feb 2022

Edited:

on 22 Feb 2022

Community Treasure Hunt

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

Start Hunting!