how to load multiple matfiles from another folder?

39 ビュー (過去 30 日間)
Suresh R
Suresh R 2021 年 10 月 28 日
回答済み: Image Analyst 2021 年 10 月 30 日
how to load multiple matfiles from another folder?
  1 件のコメント
LeoAiE
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
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 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by