This is not correct. Only if the file you are trying to run is not in the search path, Matlab will ask you whether you want to add it to the path or change the working path to the same path as where the file is located.
Yes, you’re right. Does Julia change the current directory if the file that I’m running is not in the paths? I guess not and this will remain not in the future?
Changing your current working directory for each set of data can make a lot of sense. Changing it to the location of your code is a lot more questionable, in my opinion.
Remember, it is likely that you will run the same code on many different datasets. Will you move the code around to match the location of your data? Isn’t it better to let your code work relative to whatever is the current working directory, and leave it up to the user to change directory for each dataset? (Edit: I guess you could move your data to the location of your code, but that too seems awkward to me.)
You’re absolutely right when you have many sets of data located in different places and they’re to be processed by a same file. However, I’m collaborating with others on a paper using GIT and the Julia code and the TeX files are located in two sub-folders of the main directory of this project. In other words, the relative location of these two sub-folders are fixed. We wish the figures generated by our Julia code to be saved in the sub-folder where our TeX files are. Then after my collaborators check out the updates each time, they can run the code straight away, expecting the figures are saved in the correct location that they can compile the tex file without relocating the figures. That’s why I need relative locations in this case. Hope that I have made my case understandable.
I know that I, as a user, certainly do not appreciate it when scripts start changing my working directory. I suggest that you at least automatically change the directory back after the script has finished running.
This is a good point. Now I add a line at the end of my code to change my directory back after saving the figures in the desired location.
Thank you!