MATLAB cannot save changes to the path - matlab

When starting Matlab, I must now add new paths in order to get access to my functions. However, these paths cannot be saved, and I get the following message:
“MATLAB cannot save changes to the path.
The path file, pathdef.m, might be read-only or might be in a directory for which you do not have write access.
You can save pathdef.m to a different location. In order for MATLAB to use the pathdef.m in future sessions, you need to save it in your MATLAB startup directory (the directory from which you start MATLAB).
Do you want to save pathdef.m to another location?”
Before that, it works perfectly fine.
I tried the following solutions, but none of them did work:
restart the computer
restart Matlab
start Matlab as Administrator
re-install Matlab
re-install Matlab directly in C:\ (not in C:\Programs)
share Matlab-folders
check the number of „pathdef.m“ (and there is only one)
change UAC to the smallest level
try another license
The problem seems to be between Windows and Matlab. I have Windows 8.1 Pro (64-bit), and I used Matlab 2015a.
Any help to solve the problem would be much appreciated!

Related

Where are matlab files stored which are given in documentation for trying out in browser

I have used try in browser features in matlab to run some code which are the part of documentation provided by matlab.
To explain this more simple, here is the link which lets users to try the matlab in browser.
I am trying to see those matlab files ( object3d.mat) in this case. But I cannot find any information about where are those files.
Is there anyway to download that file ('object3d.mat) ?
These mat-files come with MATLAB installation. If the MATLAB directory (including all sub-directories and files) is in your path (by default, it is) then you can use load to load it into your workspace i.e.
load object3d.mat
%or just: load object3d
If it is in your path, you can know its location using which i.e.
>> which object3d.mat
C:\Program Files\MATLAB\R2018a\toolbox\vision\visiondata\object3d.mat
>>
Note: Please make sure that you're reading the documentation of your installed MATLAB version and have the specific toolbox installed. If the documentation for the MATLAB version that you're using doesn't include that filename then it is likely that it is not available in that version.

MATLAB doesn't find files I downloaded while the script is running

My problem is as described. My script downloads files through an external call to cmd (using the system function and then .NET to make keypresses). The issue is that when it tries to fopen these files I downloaded (filenames from a text file I write as I download), it doesn't find them, causing an error. When I run the script again after seeing it fail, it works but only up to the point where it's trying to download/call new files again, where it runs into the same problem.
Are new files downloaded during when a script is running somehow not visible to the search path? Because the folder is most definitely in my search path (seeing as it works outside of during-script downloads). It's not that it isn't getting the files fast enough either, cause they appear in my folder almost instantly, and I've tried a delay to allow for it to recognize it, but that didn't work either.
I'm not sure if it's important to note that the script calls an external function which tries to read the files from the .txt list I create in the main script.
Any ideas?
The script to download the files looks like so:
NET.addAssembly('System.Windows.Forms');
sendkey = #(strkey) System.Windows.Forms.SendKeys.SendWait(strkey);
system('start cygwinbatch.bat')
pause(.1)
sendkey(callStr1)
sendkey('{ENTER}')
pause(.1)
sendkey(callStr2)
sendkey('{ENTER}')
pause(.1)
sendkey('exit')
pause(2)
sendkey('{ENTER}')
But that is not the main reason I am asking: I am confident that the downloads are occurring when the script calls them, because I see them appearing in my folder as it called. I am more confused as to why MATLAB doesn't seem to know they are there while the script is running, and I have to stop it and run it again for it to recognize the ones I've downloaded already.
Thank you,
Aaron
The answer here is probably to run the 'rehash' function. Matlab does not look for new files while executing an operation, and in some environments misses new files even during interactive activity.
Running the rehash function forces Matlab to search through its full path and determine if there are any new files.
I've never tried to run rehash in the middle of an operation though. ...
My guess is that the MATLAB interpreter is trying to look ahead and is throwing errors based on a snapshot of what the filesystem looked like before the files were downloaded. Do you get different behavior if you run it one line at a time using F9? If that's the case then you may be able to prevent the interpreter from looking ahead by using eval().

setting a default matlab path at startup

My team is trying to standardise our Matlab paths so that everyone has the same.
I have a list of the default matlab path that we should all have.
So we would like to have a script that runs when matlab opens to make sure that our paths are set to the default matlab path. So if a path has been added to our default list it will be added in the correct place.
Is this possible in Matlab?
I read about startup but that seems to do with set your working directory which is different to what I am trying to do.
You can change which directory MATLAB starts in using the userpath function so that whenever you start up MATLAB, the path will automatically redirect here.
This may be useful if you have MATLAB running on a network per se, and multiple instances can start in the same network directory.
See more from MathWorks here: http://www.mathworks.com/help/matlab/matlab_env/matlab-startup-folder.html
However, if you want to standardize everything so that everyone has access to the same path, you can use startup to add directories / folders to MATLAB's path, but if you want to complete the package, use userpath to get MATLAB to start at a specified directory.
Your startup.m file may look something like this:
addpath('/folder/to/add/one');
addpath('/folder/to/add/two');
addpath('/folder/to/add/three');
addpath('/folder/to/add/four');
Then set your userpath with the function to complete everything:
userpath('/folder/to/start');
addpath('/folder/to/start');
Also make sure you add this new folder to your startup.m file too.
Include a path or addpath line in file startup.m. For example, to add folder aaa\bbb to the path the line would be
addpath('aaa\bbb')
Note that each user may have a different startup.m file. You may need to create it, if it doesn't already exist.

Does matlab have a matlabrc file?

Today I stumbled upon this thread:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/112560
The question is basically how to make Matlab read your startup.m file regardless of where
you start your matlab session.
One of the solutions offered was:
One solution would be to ask the system administrator to add a few lines
to "matlabrc.m" that adds some pre-determined folder in the user's home
directory to the MATLAB path (say, ~/.matlabstart). Then each user can
have their own "startup.m" file inside this folder.
What I ended up doing in my system (OS X) was to add a startup.m file in:
/Applications/MATLAB_R2011a.app/toolbox/local/
In this startup.m file I added:
if exist([getenv('HOME') '/.matlabrc/startup.m'])
run([getenv('HOME') '/.matlabrc/startup.m']);
end
That way users have the option of creating the hidden folder ~/.matlabrc and inside it they can put the file startup.m. In this startup file they can tell matlab what to execute whenever they start Matlab regardless of the directory where they started it. An example of what I added to my own personal startup.m file is
addpath(genpath('/Users/jmlopez/matlabcode/'))
Now I can add as many folders inside that directory and all of them will be added
to the path every time I start Matlab automatically without having to modify the path.
The question is: Did Matlab already provided a special file like the one I created or did I just go through all this trouble to accomplish what I wanted? If the answer is the second option I gave, then, why doesn't Matlab provide this? It is such a pain in the ass to add directories to the Matlab path whenever you do not have admin permissions and I do not want to carry my startup.m file to every directory I go to. Can someone shed some light into this please?
You can save the pathdef file (which stores all the paths you add) to a custom directory. The problem however is that when matlab starts, it doesn't automatically know which custom directory you used in the previous session.
But that's where the MATLABPATH environment variable comes in. Because this allows to set the matlab starting path yourself. In linux this is simply done by setting this environment variable MATLABPATH before starting matlab (from a terminal / in your .bashrc / ...)
export MATLABPATH=$HOME/.matlab
This way you can let all users have their own pathdef file, which solves the problem of having to add them manually at startup.
EDIT
I tested out if adding startup.m to that MATLABPATH directory worked, ie: does matlab run that startup file? ... and it does. I think it doesn't work for you, because there is another startup.m file in some other (higher priority) directory (probably matlabroot), so that gets precedence. My only startup file is in MATLABPATH, so there is only one choice.
EDIT2
Nope, I added startup to matlabroot directory, and still my own startup file in .matlab gets run. Are you sure you set the MATLABPATH correctly before you started matlab?

Matlab and addpath

I have recently been working with Matlab. My question stems from my usage over a few months and is something that I can't seem to solve. I have an external SVM toolbox (OSU-SVM) that I would like to interface to with my project. I am able to get the entire system to work when I add the path of the toolbox manually (Right click -> Add to Path -> Selected Folders and Subfolders). What I would like to do is add the folder in a script. I've tried the "addpath" command but for some reason I can't get it to find the library relative to the m-file (script) that I run the command from. The following is an example of the code:
% Add OSU SVM system
addpath(genpath('./osu-svm/'));
The reason the I'd like to add the path using a relative folder to the M-file is that the code needs to run in a different environment that will not have the toolbox install. The code is also going to be executed in a different OS to the one I am developing on. That is, I am running a Windows Matlab to develop the code and need to run the finished system on a Linux machine. The process of running my files needs to be as painless as possible and shouldn't require much input from the user. That is why I'm specifically trying to avoid manual addition of the path.
On a side note a similar problem occurs when I wish to use "uigetfile" using a relative path. I believe there is something I am missing that will help me solve both of these simultaneously. Any help would be greatly appreciated.
Instead of './osu-svm/' alone use
fullfile('.','osu-svm')
The reason it does not work for you on windows is that you are using forward slash file separators. Full file will make a file string containing the correct file separator for each OS.
The genpath example in the matlab documentation also uses fullfile
http://www.mathworks.co.uk/help/techdoc/ref/genpath.html
Furthermore, the '.' is kinda unnecessary as it just means "relative to the current directory" and can be left out of the command. Perhaps you meant one directory up?
'..'
???