Hello everyone!
I would like to find a better way to use paths in Matlab. I often use Matlab scripts to postprocess data, for example by going through many text files and reading their content into Matlab for further analysis. The "problem" I have is that when I have my files in very nested locations and I move the folder containing the files and the script, I have to re-specified the whole path again in the script. I would like to specify the location of the txt files to read relative to the folder that contains the script. How can I achieve this?
Example of project folder:
C:\Users\myusername\Documents\subfolder1\subfolder2\subfolder3\myProject_Folder
'myProject_Folder' contains my txt files in a subfolder:
C:\Users\myusername\Documents\subfolder1\subfolder2\subfolder3\myProject_Folder\txt_files_Folder
and a script, for example
script.m
In script.m I have these lines for example:
outputDir = 'C:\Users\myusername\Documents\subfolder1\subfolder2\subfolder3\myProject_Folder'; %same as Project Folder
txt_files_path = ' C:\Users\myusername\Documents\subfolder1\subfolder2\subfolder3\myProject_Folder\txt_files_Folder'
I would like to have \myProject_Folder as the root folder, so that when I move myProject_Folder and its subfolders to another computer I do not have reenter all the paths again in script.m.
Thanks in advance!
Best regards,
Adriel Perez
Best Answer