How to load *.mat file from each directories in new script?
조회 수: 5(최근 30일)
I have 15 directories and in each directories, I have minimum 8 sub-directories( varies in each directories). For each directory, I have .mat file that I have saved for future use. Now, I want to develop a new script which load .mat file in each directory? How do I load .mat file from each directory? The name of .mat file is same for each directory. Any idea is highly appreciated. Thank you
Andrew Newell 2017년 4월 20일
Here is a solution that assumes there is one of these .mat files in every subdirectory of each of the 15 directories. Let's also assume that all 15 directories are all in the same directory, and fullrootdirectoryname is its name. Also, there are no other directories in that space. Then you can do the following to visit each directory and load the file:
C = strsplit(genpath(fullrootdirectoryname),':'); % Generate a list of folders
startingFolder = pwd;
The business with startingFolder makes sure you end up back where you started, and not in some unexpected place. If any of the above assumptions are not met, this code will need to be modified.