Reputation: 11
I'd like to add a new function to my Matlab so I can use it from everywhere permanently. I added the new path to the folder where I put this new function .m file. When I call this function from anywhere else, the current location moves to the folder where I have this function. How can I use the function but stay at the current folder?
Thanks.
Upvotes: 0
Views: 147
Reputation: 6789
The reason for such weird behavior is that inside mmread, the script changes the current folder by calling cd
:
currentdir = pwd;
try
if ~ispc
cd(fileparts(mfilename('fullpath'))); % FFGrab searches for AVbin in the current directory
end
...
end
if ~ispc
cd(currentdir);
end
When the script runs without error, it should return to your current folder before exiting. But if something goes wrong, it may abort without restoring the currentdir
. So I think you'd better spend time to figure out what's going wrong with the script instead of trying to restrict the script in the current folder.
Upvotes: 2
Reputation: 9532
The easiest solution is to go to your Documents
directory, where you should see a folder called Matlab
. If you put an .m
file in there, it will always be available, even if you reinstall Matlab.
Upvotes: 0