MATLAB: Load from subfolders in directory

datafolderloadMATLABsavetable

I have 429 matrices that needs to be stored in a subfolder, I call it CHARGING
I have 429 timetables hat needs to be stored in a subfolder, I call it TIMETABLES
The directory is the Desktop, where I have created the subfolders
I have issues with loading from these subfolders. I have tried
load 'TIMETABLES/Time1.mat' but that does not work
A follow up question is if it is possible to load the whole subfolder at once? So that I dont have to type load TimeXXX 429 times.

Best Answer

Are you working with Windows, Linux or MacOS?
What is the path of your Desktop folder?
Desktop = fullfile(getenv('USERPROFILE'), 'Desktop');
Data = load(fullfile(Desktop, 'TIMETABLES', 'Time1.mat'))
FileList = dir(fullfile(Desktop, 'TIMETABLES', '*.mat'));
for iFile = 1:numel(FileList)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
Data = load(File);
... process or store your data here
end
Related Question