Load from subfolders in directory

10 次查看(过去 30 天)
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.
  3 个评论
Joel Schelander
Joel Schelander 2021-3-9
Error using load
Unable to read file 'TIMETABLES/Time1.mat'. No such file or directory.
Error in DRIVE (line 8)
load 'TIMETABLES/Time1.mat'
Jan
Jan 2021-3-9
编辑:Jan 2021-3-9
The error message tells you, that there is no folder called "TIMETABLES" inside the current directory or that the file "Time1.mat" does not exist. You can check this:
isfolder('TIMETABLES')
isfile('TIMETABLES/Times1.mat')

请先登录,再进行评论。

采纳的回答

Jan
Jan 2021-3-9
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by