MATLAB: Save a file to the first folder in mathpath (the MATLAB-folder)

#mathpath #path #savefile #save #load #folder #matlab-folder

I want to save a variabel to a file and now I use the command: "save filename.mat variabel", but my problem is that I want to save this mat-file in the MATLAB-folder cause if I do so MATLAB can find it directly when you use: "load filename". I know, I can use cd(path) there "path" is the adress to the specific folder I want to save it in, but I want this to work not only for my computer and the adress to this MATLAB-folder is different on different computers and I don't want to change anything when I switch computer. The MATLAB-folder I want to save the file to I think it's always number one in "matlabpath" – the list of the folders that MATLAB is searching for files in. Can I use this information somehow? I want to get the first folder in this list and write cd(number1inthelist). I tried to write mathpath(1) but it didn't work.
Is it someone out there that can help me?

Best Answer

If your interest is to call the saved matfile without mentioning it's path: you have to create a folder and save every file you want in that..and set the path to this folder. You can use this file without mentioning its path. doc 'pathtool'