how to load multiple matfiles from another folder?
5 次查看(过去 30 天)
显示 更早的评论
how to load multiple matfiles from another folder?
1 个评论
LeoAiE
2021-10-30
Hi,
There are many ways to load multiple files into MATLAB but first and foremost is to add the folder to you path. If the files have similar names you can use a wild card with datastore function https://www.mathworks.com/help/matlab/datastore.html A datastore allows you to read and process data stored in multiple files on a disk, a remote location, or a database as a single entity. If the data is too large to fit in memory, you can manage the incremental import of data, create a tall array to work with the data, or use the datastore as an input to mapreduce for further processing.
And example of how to load multiple files If your files names are file1, file2, files3 etc Then use something like Data = readtable(‘file*.mat’) If you find this answer helpful, consider accepting it! Thanks
采纳的回答
Image Analyst
2021-10-30
See the FAQ:
% Specify the folder where the files live.
myFolder = pwd; % or 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.mat'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in with load()
s = load(fullFileName)
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!