How do I import multiple files from multiple folders?

5 ビュー (過去 30 日間)
Madison Lowe
Madison Lowe 2018 年 3 月 21 日
I am trying to import data from multiple text files spread out between multiple folders. In this example of a previous question, what could I do to grab data from every file in each folder, rather than just one particular file?
% Path of the main folder : Rotation
yourpath = 'H:\Inspection ProjectData\rotation1';
% Get all the subfolders
ContentInFold = dir(yourpath);
SubFold = ContentInFold([ContentInFold.isdir]); % keep only the directories
% Loop on each folder
MyData = [];
for i = 3:length(SubFold) % start at 3 to skip . and ..
filetoread = fullfile(yourpath,SubFold(i).name,'fx.txt'); % <- this is the "fx.txt" file of the ith subfolders
% then type your code to read the text files and store in one variable
fileID = fopen(filetoread);
MyData{end+1} = textscan(fileID,'%s\n'); % the format depends of your files
fclose(fileID);
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Preparation Basics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by