Filter löschen
Filter löschen

One Matlab version breaks when I fix errors in the other one, after getting errors in startup: Unrecognized function or variable + warning: name is nonexistent.

7 Ansichten (letzte 30 Tage)
I have multiple Matlab versions but mainly use 2019b and 2021b. Last week, I got many warnings in Matlab 2021b that said:
"Warning: Name is nonexistent or not a directory: ..." with many of the matlab21b/toolbox and matlab21b/examples folders.
Then, this error:
Error using builtin
Can't find the resource file 'toolbox/matlab/graphics/hg/hgrc.m' needed by '/export01/local/matlab21b/bin/glnxa64/libmwhg.so'
I followed the instructions and it fixed my Matlab21b; however, when I opened 2019b, it had the errors now... After fixing it, the errors returned to 2021b. So basically, my question is how can I fix both Matlab versions without breaking the other?
EDIT & SOLUTION:
The main problem was related to not being able to have an independent pathdef.m for each version, as I could only store it in my home folder (no admin rights). However, I asked the question again two years after, and I was told to use a startup.m script for both of my versions that would set up the paths that I needed and it could be accessed by both versions, so I created a file through
edit(fullfile(userpath,'startup.m'))
that looks like this:
%------------- ADD PATHS -----------------------------%
addpath /home/user/Scripts
addpath /home/user/matlab
addpath /meg/meg1/software/brainstorm3
Then I opened each of the MATLAB versions and added the startup file to the path. And now, I can add whatever path I want to without dealing with the pathdef.m file.
  2 Kommentare
Steven Lord
Steven Lord am 21 Sep. 2023
Are the two installations somehow sharing a preferences directory? What does this command show when run in each of your MATLAB installations?
prefdir
ans = '/tmp/matlabpref'
Alternately perhaps your MATLAB path is getting corrupted by each MATLAB session saving its version in the same place. What does this command show in each of your MATLAB installations?
which -all pathdef
/MATLAB/toolbox/local/pathdef.m
Zaida Escila Martínez Moreno
Hi Steven! Thank you for answering. I edited my question because I found a solution when I asked it again earlier this year.
Both versions point to different directories for both the commands that you asked:
% 2019:
prefdir
ans =
'/home/user/.matlab/R2019b'
which -all pathdef
/local/matlab19b/toolbox/local/pathdef.m
% 2021:
prefdir
ans =
'/home/user/.matlab/R2021b'
which -all pathdef
/local/matlab21b/toolbox/local/pathdef.m
However, I needed to add a specific path to both matlabs everytime, and as I don't have admin rights, I couldn't modify the original pathdef.m, so it would create a pathdef.m file in /home/user/pathdef.m. Both versions would then access the same pathdef and would run into errors.
Using a startup.m file instead fixed the problem, as both versions can use the same file without problems:
% 2019:
which startup.m -all
/home/user/startup.m
/home/user/matlab/startup.m % Shadowed
% 2021:
which startup.m -all
/home/user/startup.m
/home/user/matlab/startup.m % Shadowed

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Kshittiz
Kshittiz am 21 Sep. 2023
Hi Zaida,
I understand that you are using two MATLAB versions and encountering “Unrecognized function or variable” error while using them. You have tried using the “restoredefaultpath” command but although it solves the issue in the MATLAB version you run it in, it causes the other version to break.
You can refer to the following MATLAB Answer thread which offers guidance on adding the Path to the toolbox mentioned in the error message you are getting.
I hope this workaround will help you in resolving the issue.
Thanks and Regards,
Kshittiz
  2 Kommentare
Zaida Escila Martínez Moreno
Thank you for your response. Unfortunately, when I got those errors, I could run nothing on Matlab as it couldn't access any of its functions at all. The only way to fix it was to get rid of the pathdef.m file that was created in my home directory when I tried to add a different path. However, I did get it fixed earlier this year by doing what I included in the edit of my question.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by