필터 지우기
필터 지우기

how to load multiple matfiles from another folder?

조회 수: 4 (최근 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 CenterFile 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!

Translated by